Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.

Tags
#bloch-effective-java-2ed #equality #java
Question

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;
// Remainder omitted
}


what are the consequences of NOT implementing equals() method on ColorPoint?

equals() contract is not violated, but all color information is ignored in equality comparisons

Tags
#bloch-effective-java-2ed #equality #java
Question

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;
// Remainder omitted
}


what are the consequences of NOT implementing equals() method on ColorPoint?

?

Tags
#bloch-effective-java-2ed #equality #java
Question

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;
// Remainder omitted
}


what are the consequences of NOT implementing equals() method on ColorPoint?

equals() contract is not violated, but all color information is ignored in equality comparisons
If you want to change selection, open document below and click on "Move attachment"

#### pdfs

• owner: piotr.wasik - (no access) - Effective Java (Joshua Bloch), 2ed, p37
• owner: Jack-Rustier - (no access) - Joshua Bloch-Effective Java-Addison-Wesley (2017).pdf, p62

#### Summary

status measured difficulty not learned 37% [default] 0

No repetitions

### Discussion

Do you want to join discussion? Click here to log in or create user.