zoukankan      html  css  js  c++  java
  • java Integer类以及拆箱和装箱


    package
    com.ilaw.boson.controller; public class Demo { public static void main(String[] args) { Integer a = new Integer(2000); int b =2000; Integer c =b; System.out.println(a == b);//true,Integer和int进行操作的时候,对a进行拆箱处理 System.out.println(b == c);//true,Integer和int进行操作的时候,对c进行拆箱处理 System.out.println(a == c);//false,b进行赋值时,装箱时会调用Integer.valueOf方法对a进行装箱 a = new Integer(10); c =10; System.out.println(a == c);//false,进行行装箱操作时,会调用Integer.valueOf方法,本质两个对象对比 a=10; System.out.println(a == c);//true,两个对象都是通过装箱操来构造的,即通过Integer.valueOf方法,则如果值在-128-127之间,会从IntegerCache中取 /** * 总结: * 1.Integer和int进行操作的时候,对Integer对象进行拆箱处理 * 2.通过new的方式创建Integer对象的地址时不同的 * 3.通过Integer a=10;的方式赋值的时候会进行装箱,装箱会调用Integer的valueOf方法 * 4.Integer内部会通过IntegerCache对象来存储常用的-128-127之间Integer对象,在装箱时会返回IntegerChache的对象 * */ //说明,Integer类型和int类型进行操作(相等,相加)的时候会进行拆箱操作 } }


     总结:
     1.Integer和int进行操作的时候,对Integer对象进行拆箱处理
     2.通过new的方式创建Integer对象的地址时不同的
     3.通过Integer a=10;的方式赋值的时候会进行装箱,装箱会调用Integer的valueOf方法
     4.Integer内部会通过IntegerCache对象来存储常用的-128-127之间Integer对象,在装箱时会返回IntegerChache的对象

  • 相关阅读:
    C#快速随机按行读取大型文本文件
    OpenReadWithHttps
    fiddler不能监听 localhost和 127.0.0.1的问题 .
    C#放缩、截取、合并图片并生成高质量新图的类
    JS判断只能是数字和小数点
    HTML5 Support In Visual Studio 2010
    GridView 获取列字段的几种途径
    微信朋友圈如何同时分享(图片+文字) Android版
    【Android】 PopupWindow使用小结
    Android 第三方应用接入微信平台(2)
  • 原文地址:https://www.cnblogs.com/zhangshiwen/p/7389081.html
Copyright © 2011-2022 走看看