文章标题

https://zhuanlan.zhihu.com/p/27562748
转载自清浅池塘。

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //赋值时在-128到127之间,因此给i2赋100的时候取已有缓存好的对象赋值因此指的是一个对象。
        Integer i1=100;//Integer i1=Integer.ValueOf(100);
        Integer i2=100;//Integer i2=Integer.ValueOf(100);
        System.out.println(i1==i2);

        //超出了范围,i4赋值时候new了一个新的对象。
        Integer i3=1000;//Integer i3=Integer.ValueOf(1000);
        Integer i4=1000;//Integer i4=Integer.ValueOf(1000);
        System.out.println(i3==i4);

        Integer i7=new Integer(100);
        Integer i8=new Integer(100);
        System.out.println(i7==i8);
    }

}

true
false
false

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值