equals()
is called on specific classes like StringBuilder
or StringBuffer
.
The equals()
method is not overridden in these classes, so it may return false
even when the contents of two objects are the same.
If the reference equality is intended, it's better to use ==
to avoid confusion.
Example:
public void test(StringBuilder sb1, StringBuilder sb2) {
boolean result = sb1.equals(sb2); // Suspicious
}
New in 2017.2