hg: jdk7/tl/langtools: 6979683: inconsistent interaction of reference cast with box/unbox conversions leaves out a useful case
Hollis Waite
holliswaite at yahoo.com
Wed Sep 11 09:29:13 PDT 2013
Since Java 7 allows implicit chained casts, should it be legal to compare primitives with Objects via the '==' operator? JLS 15.21 states:
The equality operators may be used to compare two operands that
are convertible (§5.1.8) to numeric type, or two operands of
type boolean or Boolean, or two operands that are each of either
reference type or the null type. All other cases result in a
compile-time error.
However, latest JDK accepts the below code:
Object x = "";
boolean a = (3 == x);
It seems to me that the new '=' guidelines are inconsistent with official (but not *actual*) behavior of '=='. Should JLS 15.21 be updated?
More information about the compiler-dev
mailing list