Community
Participate
Working Groups
Using 3.2M1, class X { boolean foo(Long l, Float f) { return f == l; } } We report:---------- 1. ERROR in d:\tests_sources\X.java (at line 3) return f == l; ^^^^^^ Incompatible operand types Float and Long ---------- 1 problem (1 error) JLS3 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. I am not sure if this should handle this case. Since this is fine: class X { boolean foo(long l, float f) { return f == l; } } I would expect the first one to also be fine.
Comparison operators only perform boxing if exactly one operand type is primitive. However, other operations are more tolerant: public class X { float bar(Long l, Float f) { return this == null ? f : l; // both are unboxed to float } } Added AutoboxingTest#test116