What are the downsides of implementing a singleton with Java's enum?
- by irreputable
Traditionally, a singleton is usually implemented as
public class Foo1
{
private static final Foo1 INSTANCE = new Foo1();
public static Foo1 getInstance(){ return INSTANCE; }
private Foo1(){}
public void doo(){ ... }
}
With Java's enum, we can implement a singleton as
public enum Foo2
{
INSTANCE;
public void doo(){ ... }
}
As awesome as the 2nd version is, are there any downsides to it?
(I gave it some thoughts and I'll answer my own question; hopefully you have better answers)