How Java serialization deserializes final fields

Implementing readObject() or readExternal() for immutable objects is a problem. We show how the JDK uses Unsafe to assign values to final fields.

Did you ever wondered how Java serialization can set final fields of your immutable classes? If not don’t worry, most Java developers never stopped to think about it. In this post we illustrate what the question is all about. And we tell you how the JDK serialization can ignore the fact that fields are declared final and still set their value during deserialization. Not only can it sets set field values, it does so efficiently. (more…)

Continue Reading
Close Menu