Women in Technology

Hear us Roar

  Seven Low-Cost Ways to Improve Legacy Code
Subject:   using final with Serializable classes
Date:   2004-04-29 00:58:42
From:   andyp
I have a question about declaring member variables to be final in immutable classes. I agree with you that it is a trick to help the compiler enforce your own logic about the class. However when it comes to serializing these classes there is a problem. If I implement the serialization method readObject(ObjectOutputStream os), then all of the member variables that I will be setting in this method must be non-final. Do you have any suggestinos about how to have final methods in this case (without using readResolve)?
Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • using final with Serializable classes
    2004-04-29 16:20:44  Robert Simmons, Jr. | O'Reilly Author [View]

    Hmm, interesting question. However, since String uses final for its data member, I immagine the problem is solvable. I will have to play around with it.

    I will get back to you. =)