This page is no longer maintained — Please continue to the home page at www.scala-lang.org

serial version UID for anonymous class

No replies
richard emberson
Joined: 2010-03-22,
User offline. Last seen 42 years 45 weeks ago.

@serializable
@SerialVersionUID(42L)
trait Foo {
def xy: Int
override def toString: String = "Foo["+ xy + "]"
}

object Main {
val foo = new Foo {
def xy = 2
}
}

If one runs serialver against Foo one gets:

> serialver -classpath .:$SCALA_HOME/lib/scala-library.jar Foo
Foo: static final long serialVersionUID = 42L;

Running "javap -verbose Foo" one sees that the
serialVersionUID is initialized as a class variable in the
section.

Running serialver against the anonymous class:

> serialver -classpath .:$SCALA_HOME/lib/scala-library.jar 'Main$$anon$1'
Main$$anon$1: static final long serialVersionUID =
-5669638694694032459L;

No serialVersionUID was defined so serialver generated one.

Inserting a "private val serialVersionUID" creates an instance
variable.

val foo = new Foo {
private val serialVersionUID=11L
def xy = 2
}

The serialVersionUID is initialized in the section of the
javap listing.

Is there a way to assocation "@SerialVersionUID(5L)"
annotation with the anonymous class?

Thanks.

Richard

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland