Suppose we have a class that tries to cooperate with String. What is wrong with it?
public final class CaseInsensitiveString {
private final String s;
@Override public boolean equals(Object o) {
if (o instanceof CaseInsensitiveString)
return s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
if (o instanceof String)
return s.equalsIgnoreCase((String) o);
return false;
}
// rest of the code
}
Suppose we have a class that tries to cooperate with String. What is wrong with it?
public final class CaseInsensitiveString {
private final String s;
@Override public boolean equals(Object o) {
if (o instanceof CaseInsensitiveString)
return s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
if (o instanceof String)
return s.equalsIgnoreCase((String) o);
return false;
}
// rest of the code
}
Suppose we have a class that tries to cooperate with String. What is wrong with it?
public final class CaseInsensitiveString {
private final String s;
@Override public boolean equals(Object o) {
if (o instanceof CaseInsensitiveString)
return s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
if (o instanceof String)
return s.equalsIgnoreCase((String) o);
return false;
}
// rest of the code
}