Brain Teaser #1: the same but not equal
Posted by schaefa on January 16, 2004 at 12:53 AM EST
A colleque of mine just came up with the results of a test that threw me off and it took us quite some time to figure it out. So how good, do you think, are your Java skills?The class 'ABC' does not overwrite equals() method and derives directly from java.lang.Objects and everything is pure Java.
ABC a =You read right the object 'a' is the same but not equal. Does anyone knows why?; System.out.println("Is of class: " + a.getClass().getName()); // Yields to 'ABC@ System.out.println("Is the same: " + ( a == a )); // Yields to true, of course System.out.println("Is equal: " + a.equals(a)); // Yields to false ???
Hint: accept the result of equals().
Have fun - Andy
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- schaefa's blog
- 830 reads





