Created
December 16, 2012 13:39
-
-
Save martenlienen/4307371 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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