I'm trying to overwrite the equals method. Our professor, for some reason, casts the object parameter to the type class (counter).
Could somebody explain to me the logic behind that? If I instead of "Couter that = (Counter) other;" just remove that line and change "that.count" to "other.count", it executes just fine.
public class Counter {
private int count;
public Counter() {
count = 2;
}
public boolean equals(Counter other) {
if (other instanceof Counter) {
Counter that = (Counter) other;
return (this.count == that.count);
} else {
return false;
}
}
public static void main(String args []) {
Counter casio = new Counter();
Counter texas = new Counter();
System.out.println(casio.equals(texas));
}
}