Skip to content

Instantly share code, notes, and snippets.

@martenlienen
Created December 16, 2012 13:39
Show Gist options
  • Save martenlienen/4307371 to your computer and use it in GitHub Desktop.
Save martenlienen/4307371 to your computer and use it in GitHub Desktop.
class Y extends X {
public boolean equals (Object other) {
if (other == null || !(other instanceof Y)) {
return false;
}
Y y = (Y) other;
return x == y.x;
}
}
public class X {
public int x;
public static void main (String[] args) {
X x = new X();
Y y = new Y();
x.x = y.x = 5;
System.out.println(x.equals(y));
System.out.println(y.equals(x));
}
public boolean equals (Object other) {
try {
return this.x == ((X) other).x;
} catch (Exception e) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment