- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
How can I specify the "serialVersionUID" static field when serializing objects in Scala?
Created by admin on 2008-07-28.
Updated: 2008-07-28, 16:35
In Scala private values that evaluate to a constant known at compile-time are turned into private static final Java variables. This undocumented feature should do the trick for you. Just check out the implementation of lists in Scala (see e.g. src/scala/List.java
). Both classes ::
and Nil
have a field serialVersionUID
of the following form:private val serialVersionUID = <numeric literal>;
You can use any value for the numeric literal or you can do it the Java way and use serialver
for that purpose. If you want to add such an ID to a class or trait named mypackage.Foo
, you would call serialver
in the following way:
> serialver mypackage.Foo$class
For a top-level object mypackage.Obj
you write:
> serialver mypackage.Obj$