- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
serial version UID for anonymous class
Thu, 2010-09-30, 04:26
@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