-2
所以我只是在尋找澄清。我有一個equals方法,它可以通過傳入對象的cv.ch
返回實例變量而不用返回它的方法。這是怎麼回事?瞭解如何返回實例變量而無法返回它
public static class Test {
private int v;
private char ch;
public Test(int v, char ch) {
this.v= v;
this.ch= ch;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass())
return false;
Test cv = (Test) o;
if (this.v == cv.v && this.ch == cv.ch)
return true;
return false;
}
}
編輯:我改寫我的問題,使其更好地理解
*「我以爲你總是需要一種方法來返回實例變量?」 - - 這是不正確的。 –