标签:let 实现 code new with factory build enum err
/**
Singleton with public final field
**/
public class Elvis{ public static final Elvis INSTANCE = new Elvis(); private Elvis(){ ... } public void leaveTheBuilding(){ ... } }
//Singleton with static factory
public class Elvis{
private static final Elvis INSTANCE = new Elvis();
private Elvis(){ ... }
public static Elvis getInstance(){ return INSTANCE;}
public void leaveTheBuilding(){ ... }
}
//Enum singleton - the preferred approach
public enum Elvis{
INSTANCE;
public void leaveTheBuilding(){ ... }
}
标签:let 实现 code new with factory build enum err
原文地址:http://www.cnblogs.com/missdong/p/6928490.html