Acording to the Java Language Specification (15.21.3):
It is a compile-time error if it is impossible to convert the type of either operand to the type of the other by a casting conversion (§5.5). The run-time values of the two operands would necessarily be unequal (ignoring the case where both values are null).
Which means, in order to "compare" two reference types, one should be able to be cast to the other. String "is" an object, but there is no "cast" between String
and StringBuilder
.