Class
has no explicitly defined hashCode()
method, so it's not defined to be stable.
That means that you can (and probably will) get different results for MyClass.class.hashCode()
between different runs, even on the same JVM and definitely between different JVM implementations and/or versions.
This means that the serialized data from any one JVM will likely only be usable within that same JVM.
Now that might be used as an intentional way of avoiding the use of serialization for cross-VM communication (it's not a "security mechanism" or anything like that, but it can be used to quickly detect attempts to use serialization for cross-VM communication). But if that is the goal then flat out using a random number is probably better.