Since Java 5 says the best way to create a singleton is with a singleton enum type.
Example:
public enum SuperSingleton implements Zooma{ INSTANCE; /** */ public void fightTheBattle(){ System.out.println("I am fighting the battle!!!"); } @Override public void runningWild() { //This is method implemented from the Zooma interface. } }
According to Joshua Bloch, a singleton singleton singleton:
- more concise
- provides serialization machines for free
- and provides distinct from multiple instances.
I can see how much shorter it is and how it provides a monstrous character against a multiple instance , but how does it provide free serialization?
Is this something singleton gets by listing?
java enums singleton java-5
Koekiebox
source share