e hënë, 25 qershor 2007

Implementing serializable singleton

public class MySingleton implements Serializable {
static MySingleton singleton = new MySingleton();

private MySingleton() {
}

// This method is called immediately after an object of this class is deserialized.
// This method returns the singleton instance.
protected Object readResolve() {
return singleton;
}
}