If the ==
operator returns a true
will the equals()
method
return a true, always?
Yes.
The following table is a summary. Assume that each row is independent of the others.
code section | pointA == pointB | pointA.equals( pointB ) |
---|---|---|
Point pointA = new Point( 21, 17 ); Point pointB = new Point( 21, 17 ); |
false | true |
Point pointA = new Point( 21, 17 ); Point pointB = new Point( -99, 86 ); |
false | false |
Point pointA = new Point( 21, 17 ); Point pointB = pointA; |
true | true |
Will pointA.equals(pointB)
return the same true/false value as
pointB.equals(pointA)
?