// 懒汉:
public class Singleton {
private static Singleton obj = null; private Singleton() {
// TODO Auto-generated constructor stub
} public synchronized static Singleton getInstance() {
if (obj == null)
obj = new Singleton();
return obj;
}
}// 饿汉:
public class Singleton {
private static Singleton obj = new Singleton(); /**
*
*/
private Singleton() {
// TODO Auto-generated constructor stub
} public static Singleton getInstance() {
return obj;
}
}
public class Singleton {
private static Singleton obj = null; private Singleton() {
// TODO Auto-generated constructor stub
} public synchronized static Singleton getInstance() {
if (obj == null)
obj = new Singleton();
return obj;
}
}// 饿汉:
public class Singleton {
private static Singleton obj = new Singleton(); /**
*
*/
private Singleton() {
// TODO Auto-generated constructor stub
} public static Singleton getInstance() {
return obj;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货