1
我嘗試這個...Android,無法讓靜態getter setter屬性工作?
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的沒有按不能讓你有機會接觸到吸氣/吸氣器。對不起,浪費時間!!!!!!!!!!!!!!!!!!!!謝謝!!!!!!!!! – Fattie
沒問題@JoeBlow,歡迎您 –