我很難過。我想通過包含getters和setter來優化一些代碼。這是我到目前爲止有:得到並設置在Java類
public class ThingHolder {
private int updateCounter=0;
private Object theThing;
public Object getThing() {
return theThing;
}
public void setThing(Object theThing) {
this.theThing = theThing;
updateCounter++;
}
public int getUpdateCounter() {
return updateCounter;
}
和:
public class ThingHolderTester {
public static void main(String[] args) {
ThingHolder t = new ThingHolder();
t.setThing="First Object"; t.updateCounter++;
System.out.println("The thing is currently " + t.getThing + " and the ThingHolder has been updated " + t.updateCounter + " times");
t.setThing="Second Object"; t.updateCounter++;
System.out.println("The thing is currently " + t.getThing + " and the ThingHolder has been updated " + t.updateCounter + "times");
}
此刻,我不斷收到錯誤無法找到我的get和set方法的象徵。請幫忙嗎?
非常感謝你! – germantom