Have this code:
if (cs.equals(keywordUnderProcess)) {
} else {
}
Both cs
and keywordUnderProcess
is CharSequence
, has the value star
, but the else case will execute. Why? equals
check the value, isn't it?
If you read the javadoc page for the CharSequence interface, it says that the behavior for equals
is undefined:
This interface does not refine the general contracts of the equals and hashCode methods. The result of comparing two objects that implement CharSequence is therefore, in general, undefined. Each object may be implemented by a different class, and there is no guarantee that each class will be capable of testing its instances for equality with those of the other. It is therefore inappropriate to use arbitrary CharSequence instances as elements in a set or as keys in a map.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With