【发布时间】:2016-11-28 19:58:24
【问题描述】:
我正在尝试这个......
public class Info {
private static Info ourInstance = new Info();
public static Info getInstance() { return ourInstance; }
private static int currentIndex;
public static void setCurrentIndex(int i) {
Log.d("DEV", "setter!");
currentIndex = i;
// do other work here
}
public static int getCurrentIndex() {
Log.d("DEV", "getter!");
return currentIndex;
}
private Info() {
Log.d("DEV", "class initialized no problem...");
currentIndex = 42; // just doesn't work, only sets the field
}
}
在任何其他类...
Info.currentIndex = 666; // just doesn't work
它只是不起作用 - 可能是什么问题?什么都试过了。
【问题讨论】:
标签: java android properties getter-setter