The compiler tries to help you.
When the ==
can never be true because of conflicting types, it assumes you made a mistake and will refuse to compile the code.
Happens with instanceof
as well, and also with casts.
String a = null;
if (a instanceof StringBuilder){} // compile-error
StringBuilder b = (StringBuilder) a; // compile-error