代码如下:
public enum SingleTon {
INSTANCE;
public static SingleTon getInstance(){
return INSTANCE;
}
}
///测试代码:
SingleTon s1 = SingleTon.getInstance();
SingleTon s2 = SingleTon.getInstance();
if(s1 == s2){
System.out.println("yes");
}
else{
System.out.println("no");
}