Share this page 

Have a singletonTag(s): Language


A singleton is a class that can be instantiated only one time in a JVM. Repeated calls always return the same instance.
public class OnlyOne{
    private static OnlyOne one = new OnlyOne();

    private OnlyOne(){}

    public static OnlyOne getInstance() { return one; }
} 
To use it
OnlyOne myOne = OnlyOne.getInstance();