Java 7将自动装箱应用于int。
private boolean compare(java.lang.Object, int);
Code:
0: aload_1
1: iload_2
2: invokestatic #2 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
5: if_acmpne 12
8: iconst_1
9: goto 13
12: iconst_0
13: ireturn
我用build 1.7.0_71-b14创建了这个
编辑:
此行为被Oracle识别并视为错误:
JDK-8013357:Javac接受错误的二进制比较操作
Relevant JLS section is 15.21. Javac seems to treat this as a
reference comparison, but a reference comparison is only allowed when
BOTH operands are reference types.
…
The type rules for binary comparisons in JLS Section 15.21 will now be
correctly enforced by javac. Since JDK5, javac has accepted some programs with Object-primitive comparisons that are incorrectly typed according to JLS 15.21. These comparisons will now be correctly identified as type errors.