Integrate cache的易错点

来源:互联网 发布:童装淘宝店简介怎么写 编辑:程序博客网 时间:2024/06/08 16:47
public class Test{    public static void main(String[] args)    {                Integer  a=100;        Integer b=100;        Integer c=new Integer(100);        Integer d=new Integer(100);        System.out.println(a==b);//true        System.out.println(c==d);//false                String  e="a";        String f="a";        String i=new String("a");        String j=new String("a");        System.out.println(e==f);//true        System.out.println(i==j);//false        /**         *          */        Integer  f1=127,f2=127,f3=128,f4=128;        System.out.println(f1==f2);//true        System.out.println(f3==f4);//false        System.out.println(-f1==-f2);//true        System.out.println(-f3==-f4);//true            }}
简单地解释这段代码,就是如果传入的int在IntegerCache.low和IntegerCache.high之间,那就尝试看前面的缓存中有没有打过包的相同的值,如果有就直接返回,否则就创建一个Integer实例。
IntegerCache.low 默认是-128;IntegerCache.high默认是127.


原创粉丝点击