In a world before Java 1.5 (so no enum
) and with my object being serialized, how can I enforce proper instance control? I\'m talking about a class like this, w
If I understand you correctly then what you are looking for is to take Joshua Bloch' advice and implement the readResolve method to return one of your constant instances.
private Object readResolve() throws ObjectStreamException {
return PRIVATE_VALUES[ordinal]; // The list holding all the constant instances
}