美文网首页
Way To JAVA-1.1编译之自动装箱和拆箱

Way To JAVA-1.1编译之自动装箱和拆箱

作者: IAmWhoAmI | 来源:发表于2016-07-13 14:22 被阅读7次
    public static void main(String[] args){
        Integer a =1;
        Integer b =2;
        Integer c =3;
        Integer d =3;
        Integer e =321;
        Integer f =321;
        Long g = 3L;
        System.out.println(c==d);//true
        System.out.println(e==f);//false
        System.out.println(c==(a+b));//true
        System.out.println(c.equals(a+b));//true
        System.out.println(g==(a+b));//true
        System.out.println(g.equals(a+b));//false
    }
    
    public static void main(String[] args) {
        Integer a = Integer.valueOf(1);
        Integer b = Integer.valueOf(2);
        Integer c = Integer.valueOf(3);
        Integer d = Integer.valueOf(3);
        Integer e = Integer.valueOf(321);
        Integer f = Integer.valueOf(321);
        Long g = Long.valueOf(3L);
        System.out.println(c == d);//这个时候比较的是地址
        System.out.println(e == f);
        System.out.println(c.intValue() == a.intValue() + b.intValue());
        System.out.println(c.equals(Integer.valueOf(a.intValue() + b.intValue())));
        System.out.println(g.longValue() == (long)(a.intValue() + b.intValue()));
        System.out.println(g.equals(Integer.valueOf(a.intValue() + b.intValue())));
    }
    

    相关文章

      网友评论

          本文标题:Way To JAVA-1.1编译之自动装箱和拆箱

          本文链接:https://www.haomeiwen.com/subject/iebsjttx.html