证明

service

1
2
3
4

public interface {
public void test();
}

SingletonServiceImpl

1
2
3
4
5
6
7
8
9
10
11
12
13

public class SingletonServiceImpl implements {
public static int count = 0;
/*构造函数 若非单例则count会一直 +1*/
public SingletonServiceImpl(){
count++;
}
@Override
public void test() {
System.out.println(this);
System.out.println(count);
}
}

结果:

[email protected]
1
[email protected]
1