本帖最后由 wangdeyun 于 2011-11-23 09:23 编辑
- class Single {
- private static Single s = null;
- private Single() {}
- public static Single getInstance() {
- if (s == null) {
- synchronized (Single.class)
- {
- if (s == null)
- s = new Single();
- }
- }
- return s;
- }
- }
复制代码 synchronized (Single.class)中Single.class可以 用this代替吗?
synchronized()括号里面传的是对象,那Single.class可以理解成Single的一个实例对象吗?
|