@DatapublicclassUser{private Integer no ;private Integer age ;private String name ;//构造函数私有化,防止被外部实例化privateUser(){}//静态内部枚举,维护唯一实例staticenum Single{
SINGLE;private User user;privateSingle(){this.user =newUser();}}//对外提供获取唯一实例方法publicstatic User instance(){return Single.SINGLE.user;}}publicclassTest{publicstaticvoidmain(String[] args){
User instance = User.instance();
System.out.println("instance = "+ instance);
User instance1 = User.instance();
System.out.println("comparator = "+(instance1==instance));//true}}