public class DicGender {
public static final Integer MALE = 0;
public static final Integer FEMALE = 1;
private static DicGender instance = null;
private static LinkedHashMap<Integer, String> dicMap = null;
private DicGender(){
dicMap = new LinkedHashMap<>();
dicMap.put(MALE, "男");
dicMap.put(FEMALE, "女");
}
public static DicGender getInstacne(){
if (instance == null)
{
instance = new DicGender();
}
return instance;
}
//注意该方法是"对象"的方法。
public LinkedHashMap<Integer, String> getDicMap() {
//这里定义得到的该字典类的副本
return (LinkedHashMap<Integer, String>)dicMap.clone();
}
}
//调用伪代码
{
LinkedHashMap<Integer, String> dicMap = DicGender.getInstacne().getDicMap()
}