Jestem nowicjuszem w Javie i pracowałem nad tym ćwiczeniem przez jakiś czas, ale nadal otrzymuję błąd: int nie może być dereferencjonowany. Widziałem kilka podobnych pytań, ale wciąż nie mogę zrozumieć mojej własnej sprawy. Oto pełna kody:Nowość w Javie i występuje błąd "int nie można dereferencjonować"
package inclass;
class OneInt {
int n;
OneInt(int n) {
this.n = n;
}
@Override public boolean equals(Object that) {
if (that instanceof OneInt) {
OneInt thatInt = (OneInt) that;
return n.equals(thatInt.n); // error happens here
} else {
return false;
}
}
public static void main(String[] args) {
Object c = new OneInt(9);
Object c2 = new OneInt(9);
System.out.println(c.equals(c2));
System.out.println(c.equals("doesn't work"));
}
}
Dziękuję bardzo za pomoc mi z tym trochę kłopotów.