JVM Languages
jqa0502.txt
Associated article: Java Q&A: How Do I Correctly Implement the equals() Method?
Tags: JVM Languages
Published source code accompanying the article by Tal Cohen in which he shows how you can correctly implement the Java equals() method.
Java Q&A
by Tal Cohen
Listing One
class Point {
private int x;
private int y;
// (obvious constructor omitted...)
public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return (p.x == this.x &...


