第一种:
第二种:
第三种:
public class A
{
private static final A instance = new A();
private A()
{
}
public static A getInstance()
{
return instance;
}
}
第二种:
public class A
{
private static A instance = null;
private A()
{
}
public static A getInstance()
{
if (null == instance)
{
synchronized (A.class)
{
if (null == instance)
{
instance = new A();
}
}
}
return instance;
}
}
第三种:
public enum A
{
instance;
private A()
{
}
public static A getInstance()
{
return instance;
}
}