单例模式
private static HttpUtil instance;
public static synchronized HttpUtil getInstance() {
if (instance == null) instance = new HttpUtil();
return instance;
}
本文介绍了一种使用Java语言实现单例模式的方法。通过静态变量和同步方法确保了类的单一实例,并提供了一个全局访问点。
单例模式
private static HttpUtil instance;
public static synchronized HttpUtil getInstance() {
if (instance == null) instance = new HttpUtil();
return instance;
}

被折叠的 条评论
为什么被折叠?