Java – how to add @ serialVersionUID to an anonymous class?
•
Java
I want to translate the following code from Java to scala:
Foo foo = new Foo() { private static final long serialVersionUID = 12345L; }
Foo class is an abstract class
What about the equivalent code in scala?
Solution
There is a Scala annotation for adding the ID. however, it seems that you cannot apply this solution to anonymous inner classes However, according to the scala FAQ:
code
object Ser extends Application { trait Foo { def xy: Int } val x = new Foo with java.io.Serializable { def xy = 2; private val serialVersionUID = 1L } }
Use 2.8 The compiler compiles well I haven't tested it yet, although the serial version of the result class is actually provided
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码