Duplicate :
|
boolean b = ((Object)null == 3); should not compile since it's not a numerical equality test (JLS15.21.1) nor a boolean equality test (15.21.2) nor a reference equality test (15.21.3). Indeed, it does not compile. boolean b = (3 == (Object)null); should not compile for exactly the same reason, but does compile! I am told javac performs a boxing conversion followed by a widening reference conversion, which isn't a valid combination allowed under casting conversion (mentioned in 15.21.3), so I am not sure what javac is trying to do.