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

    }

  • 相关阅读:
    980不同路径III
    输入函数
    IDEA更新maven依赖包
    join()函数
    方差偏差困境
    np.bincount()函数
    72编辑距离
    741摘樱桃
    523连续的子数组和
    1306跳跃游戏III
  • 原文地址:https://www.cnblogs.com/robert-zhang/p/9143111.html
Copyright © 2011-2022 走看看