Suppose we have a class
public class Point {
private final int x;
private final int y;
@Override public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return p.x == x && p.y == y;
}
// Remainder omitted
}
and a subclass
public class ColorPoint extends Point {
private final Color color;
@Override public boolean equals(Object o) {
if (!(o instanceof ColorPoint))
return false;
return super.equals(o) && ((ColorPoint) o).color == color;
}
// Remainder omitted
}
what are the consequences of implementing equals() method on ColorPoint like above?
Suppose we have a class
public class Point {
private final int x;
private final int y;
@Override public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return p.x == x && p.y == y;
}
// Remainder omitted
}
and a subclass
public class ColorPoint extends Point {
private final Color color;
@Override public boolean equals(Object o) {
if (!(o instanceof ColorPoint))
return false;
return super.equals(o) && ((ColorPoint) o).color == color;
}
// Remainder omitted
}
what are the consequences of implementing equals() method on ColorPoint like above?
Suppose we have a class
public class Point {
private final int x;
private final int y;
@Override public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return p.x == x && p.y == y;
}
// Remainder omitted
}
and a subclass
public class ColorPoint extends Point {
private final Color color;
@Override public boolean equals(Object o) {
if (!(o instanceof ColorPoint))
return false;
return super.equals(o) && ((ColorPoint) o).color == color;
}
// Remainder omitted
}
what are the consequences of implementing equals() method on ColorPoint like above?
status | not learned | measured difficulty | 37% [default] | last interval [days] | |||
---|---|---|---|---|---|---|---|
repetition number in this series | 0 | memorised on | scheduled repetition | ||||
scheduled repetition interval | last repetition or drill |