java8 object比较_为什么在Java 7中有一个int到object比较有效,但是在Java 8中不行?...

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值