serialVersionUID applies only to classes that generate a stream identifier . This is not the case if the serializable class has a writeReplace() method (also described in the Serializable documentation ) that returns a replacement object of another class, since such a representation is completely separate from the original class. This is what happens with serializable instances of lambda, see SerializedLambda :
It is assumed that developers of serializable lambdas, such as compilers or runtime libraries, ensure that instances are deserialized properly. One of them is to ensure that the writeReplace method returns an instance of SerializedLambda , rather than allowing default serialization.
So, its instance is SerializedLambda , which gets into the stream, and therefore the responsibility of this class is to have a stable serialized representation. Unfortunately, this does not protect you from possible incompatibilities.
After deserialization, a synthetic class method will be called that defines the lambda expression (compare this answer as well ), which will reject deserialization attempts that do not match the existing definition of the lambda expression inside this class, while the match may depend on the subtle aspects of the definition of lambda. Note that even recompiling the defining class with Eclipse rather than javac can break Serialization compatibility.
Not affected by the security impact of Serializable lambdas . As a rule, I recommend not using it.
Holger
source share