Utilice instanceof en equals() antes de la
conversión.
public InstanceofEquals_Solution( String str ) {
super();
this .str = str;
}
public String getString(){
return str;
}
public int hashCode() {
return str.hashCode();
}
public boolean equals(Object other) {
return ( other instanceof InstanceofEquals_Solution) &&
str.equals( ( (InstanceofEquals_Solution)other ).getString() );
}
private String str;
|
|