In Android, You sometimes get CharSequence as a parameter of a callback.
It might be tempting to check for equality using “equals” method of a String.
But this would be a bug:
"SomethingSomething".equals(myCharSequence)
because equals requires the other object to be an instance of String as well, as explained in JavaDoc of String.equals :
public boolean equals(Object anObject) Compares this string to the specified object. The result istrue
if and only if the argument is notnull
and is aString
object that represents the same sequence of characters as this object.
The correct way would be to use contentEquals:
"SomethingSomething".contentEquals(myCharSequence)