As it turned out, it is impractical to compare the primitive with an expression such as the compilation time "Object". JLS 15.21 expressly forbids:
Equality operators can be used to compare two operands that are convertible ( ยง5.1.8 ) to a numeric type or two operands of type boolean or Boolean, or two operands, each of which has either a reference type or a null type. All other cases lead to a compile-time error.
The Eclipse compiler places an error regardless of the version of Java. For Java 7, both Oracle JDK and OpenJDK mistakenly allow you to compile code. This bug in Oracle and Open JDK is fixed in version 8.
Thus, this elusive comparison is illegal according to the specification and will compile only some subsets of compilers for a specific subset of the purposes of the language version. Will never work on Java 4- or 8+. The casting conversions mentioned in the other answers only apply to the '=' operator, not to '=='. 15.21.3 applies only to two reference operands.
source share