[PATCH 1/1] RFC: Add a couple more trivial set methods to java.util.Collections

Tom Hawtin Thomas.Hawtin at Sun.COM
Thu Dec 4 18:51:45 UTC 2008

David M. Lloyd wrote:
> BTW, I'm sceptical about the claims within the javadoc for singleton() 
> that the resultant set is serializable, as the field containing the 
> element is final.

final is fine with serialisation. You can even provide a readObject and 
set it with ObjectInputStream.readObject (but only once!). However, you 
can't use readFields and then attempt to assign it (if you want to do 
that then you'll need readResolve - use a "serial proxy" as described in 
Effective Java 2nd Ed.).


More information about the core-libs-dev mailing list