/**
* 标准的饿汉式单例设计模式
*/
public enum DemoTest {
DEMO_TEST("a","b");
private String name;
private String age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
DemoTest(String name, String age) {
this.name = name;
this.age = age;
}
}
/**
* 标准的懒汉式设计模式
*/
public class DemoTest2 {
private String name;
private DemoTest2(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public DemoTest2 ok(){
DemoTest2 demoTest2 = new DemoTest2();
demoTest2.setName("");
return demoTest2;
}
}