当前位置: 首页 > news >正文

手机wap网站大全小程序开发公司加盟

手机wap网站大全,小程序开发公司加盟,徐州鸿美网站建设,江苏城市建设档案馆网站一、装箱、拆箱定义如果一个int型量被传递到需要一个Integer对象的地方#xff0c;那么#xff0c;编译器将在幕后插入一个对Integer构造方法的调用#xff0c;这就叫做自动装箱。而如果一个Integer对象被放到需要int型量的地方#xff0c;则编译器将幕后插入一个队intValu…一、装箱、拆箱定义如果一个int型量被传递到需要一个Integer对象的地方那么编译器将在幕后插入一个对Integer构造方法的调用这就叫做自动装箱。而如果一个Integer对象被放到需要int型量的地方则编译器将幕后插入一个队intValue方法的调用这就叫做自动拆箱。public static voidmain(String[] args) {//装箱Integer i1 Integer.valueOf(1);//自动装箱Integer i2 1;//默认执行valueOf(1);System.out.println(i1 i2);//true//自动拆箱int i3 i1.intValue();int i4 i2.intValue();System.out.println(i3 i4);//true//超出Integer的缓存范围不从私有静态内部类IntegerCache的数组cache中获得通过new返回新对象Integer i5 128;Integer i6 -129;Integer i5_1 128;Integer i6_1 -129;System.out.println(i5 i5_1);//falseSystem.out.println(i6 i6_1);//false}所以说对于-127~127之间的值Integer对象中存在一个IntegerCache的私有静态内部类这个内部类有一个Integer类型的静态常量数组在这个内部类中通过静态方法块初始化了这个静态常量数组。默认这个数组保存[-127,128)之间的Integer对象。源码如下1 private static classIntegerCache {2 static final int low -128;3 static final inthigh;4 static finalInteger cache[];56 static{7 //high value may be configured by property8 int h 127;9 String integerCacheHighPropValue 10 sun.misc.VM.getSavedProperty(java.lang.Integer.IntegerCache.high);11 if (integerCacheHighPropValue ! null) {12 try{13 int i parseInt(integerCacheHighPropValue);14 i Math.max(i, 127);15 //Maximum array size is Integer.MAX_VALUE16 h Math.min(i, Integer.MAX_VALUE - (-low) -1);17 } catch( NumberFormatException nfe) {18 //If the property cannot be parsed into an int, ignore it.19 }20 }21 high h;2223 cache new Integer[(high - low) 1];24 int j low;25 for(int k 0; k cache.length; k)26 cache[k] new Integer(j);2728 //range [-128, 127] must be interned (JLS7 5.1.7)29 assert IntegerCache.high 127;30 }3132 privateIntegerCache() {}33 }通过下面的源码可以知道为什么Integer i 128;与Integer y 128;通过比较的结果为false。如果要赋值的int变量在范围内则返回数组中的对象给Integer如果不在则通过带参构造方法new一个新的Integer对象。1 public static Integer valueOf(inti) {2 if (i IntegerCache.low i IntegerCache.high)3 return IntegerCache.cache[i (-IntegerCache.low)];4 return newInteger(i);5 }二、其它包装类型The Java Language Specification, 3rd Edition 写道为了节省内存对于下列包装对象的两个实例当它们的基本值相同时他们总是Boolean 全部缓存Byte 全部缓存Character 127缓存Short (-128,127)缓存Long (-128,127)缓存Float (没有缓存)Double (没有缓存)其中Character的缓存源码1   private static classCharacterCache {2 privateCharacterCache(){}34 static final Character cache[] new Character[127 1];56 static{7 for (int i 0; i cache.length; i)8 cache[i] new Character((char)i);9 }10 }其中Float没有缓存直接返回源码1   public static Float valueOf(String s) throwsNumberFormatException {2 return newFloat(parseFloat(s));3 }三、用处除了包装类提供了额外的方法外当使用集合框架时泛型为Object类型所以如果声明为List list...则这样是不行的必须声明为List list...。四、存储的位置因为是对象所以存储在堆中。
http://www.pierceye.com/news/914197/

相关文章:

  • html5手机网站源码网站备案要如何取消
  • 商城建设网站制作微信网站模板源码
  • 品牌型网站制作公司想做百度推广找谁
  • 浙江建设监理协会官方网站网站建设的公司选择哪家好
  • 优秀网站及网址沙漠风网站建设6
  • 做数据表格的网站出口网站建设方案
  • 广州网站建设信息科技有限公司福建省亿力电力建设有限公司网站
  • 电子商务网站开发 ppt湛江做网站报价
  • 网站建设框架图wordpress 固定链接设置
  • 内蒙古工程建设协会网站seo文章外包
  • 网站建设免费的服务器商丘推广公司
  • 网站设计大概价格设计网络平台的公司
  • phpcms中的网站介绍页中文去掉wordpress
  • 网站的建设心得怎么做网站淘宝转换工具
  • 做网站1天转多钱wordpress 分享插件
  • 淘宝网站建设单子好接吗朝阳区办公
  • html5网站建设平台怎么给网站添加图标
  • 中文域名网站网站制作wap页面
  • wordpress站内全文检索一个人完成网站建设
  • wordpress自定义重用结构北京seo怎么优化
  • 苏州做网站专业的公司vs2008怎么做网站
  • 效果好的徐州网站建设休闲食品网站建设策划书
  • 如何发布自己的网站wordpress 4.9.6 下载
  • 织梦网站打开慢企业咨询师资格证
  • 蓬莱网站建设哪家好广州白云网站建设
  • 网站建设得花多少钱做购物网站能否生存
  • 多语言网站 用什么cms深圳Wordpress网站
  • 常州市建设工程质量监督站网站开发公司设计管理岗位述职
  • 国外网站顶部菜单设计谷歌seo文章
  • 梅州网站开发外国自适应企业网站