美文网首页
Java自动装箱,拆箱

Java自动装箱,拆箱

作者: lcwcloud | 来源:发表于2018-03-20 20:44 被阅读0次

    1.装箱:自动将基本数据类型转换为包装器类型 拆箱:将包装器类型转化为基本数据类型

    基本数据类型  包装器类型

    int(4bytes)    Integer

    byte(1byte)    Byte

    short(2bytes)    Short

    long(8bytes)    Long

    float(4bytes)  Float

    double(8bytes)  Double

    char(2bytes)    Character

    boolean(1bit)  Boolean

    2.Integer i = 1; 实际执行的是:Integer i = new Integer(1);

    int t = i;实际执行的是:int t = i.valueOf();

    equals比较两个对象的值是否相等,==比较两个对象的地址是否相等,也可用于比较两个基本数据类型的变量值是否相等。

    相关文章

      网友评论

          本文标题:Java自动装箱,拆箱

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