使用枚举类:
public enum SingleTonEnum {
INSTANCE;
private String str;
SingleTonEnum() {
}
public void setStr(String str) {
this.str = str;
}
public String getStr() {
return str;
}
}
使用:
private void testSingleTonEnum() {
SingleTonEnum singleTonEnum1 = SingleTonEnum.INSTANCE;
SingleTonEnum singleTonEnum2 = SingleTonEnum.INSTANCE;
singleTonEnum1.setStr("123");
Log.i(TAG, singleTonEnum1.getStr() + " " + singleTonEnum2.getStr());
singleTonEnum2.setStr("456");
Log.i(TAG, singleTonEnum1.getStr() + " " + singleTonEnum2.getStr());
Log.i(TAG, (singleTonEnum1 == singleTonEnum2) + "");
}