<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
/**
*单例模式主要作用是在java应用程序中,一个类只有一个实例存在。
*/
public class Singleton{
private Singleton(){
}
private final static Singleton instance = new Singleton();
public static Singleton getInstance(){
return instance;
}
}
或者如下
*单例模式主要作用是在java应用程序中,一个类只有一个实例存在。
*/
public class Singleton{
private Singleton(){
}
private final static Singleton instance = new Singleton();
public static Singleton getInstance(){
return instance;
}
}
或者如下
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
/**
*单例模式主要作用是在java应用程序中,一个类只有一个实例存在。The Second Way
*/
public class Singleton{
private static Singleton instance = null ;
public static synchronized Singleton getInstance(){
if (instance == null ) instance = new Singleton();
return instance;
}
}
*单例模式主要作用是在java应用程序中,一个类只有一个实例存在。The Second Way
*/
public class Singleton{
private static Singleton instance = null ;
public static synchronized Singleton getInstance(){
if (instance == null ) instance = new Singleton();
return instance;
}
}