I am new to java and have been working on this exercise for a while, but keep getting the error: int cannot be dereferenced. I saw a couple of similar questions, but still can not understand my own case. Here are the full codes:
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);
} 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"));
}
}
Thanks for helping me with this little nuisance.
source
share