previous |
start |
next
Object Comparison
- == tests for identity, equals for identical
content
- Rectangle cerealBox = new
Rectangle(5, 10, 20, 30);
Rectangle oatmealBox = new
Rectangle(5, 10, 20, 30);
Rectangle r = cerealBox;
- cerealBox != oatmealBox,
but cerealBox.equals(oatmealBox)
- cerealBox == r
- Caveat: equals must be defined for the class (see
chapter 11)
previous |
start |
next