zoukankan      html  css  js  c++  java
  • Java坑人面试题之自动装箱和拆箱后的引用数据类型和基本数据类型的计算

    在Java1.5以后的版本中,引用类型Integer和基本数据类型int之间是可以通过自动装箱和拆箱进行计算的

    例如: Integer in = 1; //it means  Integer in = new Integer(1);

    in = in +1;// Integer type in convert to int type  via function Integer.intValue()

    //in+1 =  in.intValue(1) + 1;

    So, in = 2; //auto picking : pass Integer(2) = Interger in;

    public static void functin2() {
    Integer i = new Integer(1);
    Integer j = new Integer(1);
    System.out.println(i==j);//false
    System.out.println(i.equals(j));//true

    Integer a = 500;
    Integer b = 500;
    System.out.println(a==b);//false
    System.out.println(a.equals(b));//true


    //when the data in the scope of byte(127),JVM will not create new object
    Integer aa = 50;
    Integer bb = 50;
    System.out.println(aa==bb);//true
    System.out.println(aa.equals(bb));//true

    }

  • 相关阅读:
    Dolls
    无题II hdu 2236(二分枚举区间)
    Cyclic Nacklace
    剪花布条
    Oulipo
    最短路
    Bzoj3211花神游历各国
    Zjoi2010排列计数Perm
    Zjoi2011看电影(movie)
    关于一次同余方程的一类解法(exgcd,CRT,exCRT)
  • 原文地址:https://www.cnblogs.com/robert-zhang/p/9143111.html
Copyright © 2011-2022 走看看