class Singleton{
private Singleton{}
private final static Singleton instance = new Singleton();
public static Singleton getInstance(){
return instance;
}
}
class Singleton{
private Singleton{}
private static Singleton instance
static{
instance = new Singleton();
}
public static Singleton getInstance(){
return instance;
}
}
class Singleton{
private static Singleton instance;
private Singleton{
}
public static Singleton getInstance(){
if(instance == null){
instance = new instance();
}
return instance;
}
}
class Singleton{
private static Singleton instance;
private Singleton(){
}
public static synchronized Singleton getInstance(){
if(instance == null){
instance = new Singleton();
}
return instance;
}
}
class Singleton{
private static Singleton instance;
private Singleton(){
}
public static Singleton getInstance(){
if(instance == null){
synchronized(Singleton.class){
instance = new Singleton();
}
}
return instance;
}
}
class Singleton{
private static volatile Singleton instance;
private Singleton(){
}
public static Singleton getInstance(){
if(instance == null){
synchronized(Singleton.class){
if(instance == null){
instance = new Singleton();
}
}
}
return instance;
}
}
class Singleton{
private Singleton{
}
private static class SingletonInstance{
public static final Singleton instance = new Singleton();
}
public static Singleton getInstance(){
return SingletonInstance.instance;
}
}
public static class SingletonObject {
private SingletonObject(){
}
private enum Singleton{
INSTANCE;
private final SingletonObject instance;
private Singleton(){
instance = new SingletonObject();
}
private SingletonObject getInstance(){
return instance;
}
}
public static SingletonObject getInstance(){
return Singleton.INSTANCE.getInstance();
}
}