By Alvin Alexander. Last updated: July 27, 2020
If you ever need to look at the SerialVersionUID
field in a Scala or Java class, I can confirm that this approach works:
println(java.io.ObjectStreamClass.lookup(sheep.getClass()).getSerialVersionUID())
For instance, given this Scala class:
@SerialVersionUID(125L) class Sheep(val name: String) extends Serializable { override def toString = name val greet: String = { s"Hello, $name" } }
If you create an instance of that class named sheep and then run the println
statement, you’ll see the number 125. I also confirmed that this works if you serialize and deserialize this object.