NotSerializableException on anonymous class

Joshua Bloch writes in his book Effective Java, 2nd Edition, Item 74:

Inner classes should not implement Serializable. They use compiler-generated synthetic fields to store references to enclosing instances and to store values of local variables from enclosing scopes. How these fields correspond to the class definition is unspecified, as are the names of anonymous and local classes. Therefore, the default serialized form of an inner class is illdefined. A static member class can, however, implement Serializable.

Leave a Comment