package Test2;
public class Sigleton {
private static Sigleton sigleton=new Sigleton();
private static int count1;
private static int count2=0;
public Sigleton(){
System.out.println("you");
count1++;
count2++;
}
public static Sigleton getInstance(){
System.out.println("fuck");
return new Sigleton();
}
public static void main(String[] args) {
Sigleton t=Sigleton.getInstance();
System.out.println(t.count1);
System.out.println(t.count2);
}
}
运行一下就知道为什么
public class Sigleton {
private static Sigleton sigleton=new Sigleton();
private static int count1;
private static int count2=0;
public Sigleton(){
System.out.println("you");
count1++;
count2++;
}
public static Sigleton getInstance(){
System.out.println("fuck");
return new Sigleton();
}
public static void main(String[] args) {
Sigleton t=Sigleton.getInstance();
System.out.println(t.count1);
System.out.println(t.count2);
}
}
运行一下就知道为什么