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

如东做网站公司网络营销属于哪个专业

如东做网站公司,网络营销属于哪个专业,学校专业建设规划,莱芜手机网站建设报价目录 前言 一、自动装箱与拆箱(以 Integer 包装类为例) 二、再来看看几个示例 ​三、Double ,Float 类型亦是如此吗? 四、补充 前言 小伙伴们大家好,日常使用业务层方面的代码居多,但也不可忘了基本的一些代码格式…


目录

前言

一、自动装箱与拆箱(以 Integer 包装类为例)

二、再来看看几个示例

​三、Double ,Float 类型亦是如此吗?

四、补充


前言

        小伙伴们大家好,日常使用业务层方面的代码居多,但也不可忘了基本的一些代码格式以及原理,比如最近看到的一种题型,这里就涉及到了自动装箱的基础知识了

        Integer i = new Integer(10);Integer j = 10;Integer k = 10;System.out.println(i == j);   //falseSystem.out.println(k == j);   //true

一、自动装箱与拆箱(以 Integer 包装类为例)

        1、装箱就是自动将基本数据类型转换为包装器类型( int >> Integer),调用Integer.valueOf(int )方法

        2、拆箱就是反过来,将包装器类型转换为基本数据类型,调用了Integer.intValue方法

        3、java并不是一开始就支持自动拆装,查了下是在Java SE5之后才支持该功能

        自动装箱之后写法对比

        Java SE5之前:Integer i = new Integer(10);

        Java SE5之后:Integer i = 10;

二、再来看看几个示例

        1.比如前言中提到的 i 和 j 为什么不相等?

Integer i = new Integer(10)

         创建了一个新的Integer对象,而Integer j = 10; 则会自动装箱,实际上会调用Integer Integer j = 10

        实际上进行了装箱操作,相当于调用了Integer.valueOf(10)                 

        而由于10在缓存范围内,因此会复用缓存中的对象。

i和j虽然表示的是相同的值,但是i和j指向的是不同的对象,所以表达式 i == j 的结果是false

        2.通过new 关键字生成的Integer对象比较

        Integer i = new Integer(127);Integer j = new Integer(127);System.out.println(i == j);   //false

 ij 分别是通过 new Integer(127) 创建的两个不同的对象,会被强制创建为新的对象,而不是从缓存中获取。即使值相同,但它们在内存中的位置不同,因此比较 i == j 会返回 false

        3.Integer.valueOf 方法缓存的对象大小区间

        Integer k = 10;Integer l = Integer.valueOf(10);Integer l1 = Integer.valueOf(128);System.out.println(k == l);   //trueSystem.out.println(k == l1);  //false

Integer k = 10;

Integer l = Integer.valueOf(10);

    这两行代码执行时,都会将值为10的整数赋给Integer对象。在Java中,对于数值范围在-128到127之间的整数,会被缓存起来,所以当你比较 k == l 时,因为10在缓存范围内,它们实际上指向的是同一个对象,所以返回true。

          而当比较 k == l1 时,因为128不在缓存范围内,所以 Integer.valueOf(128) 会创建一个新的Integer对象,与 Integer k = 10; 创建的对象不同,因此返回false。

        来看下 Integer.valueOf 方法内部 ,制定了数值范围如果是在[-128,127]之间,返回IntegerCache缓存中已经存在的对象的引用,否则创建一个新的 Integer对象,所以k 和 l 指向的是同一个对象,k 和 l1 分别指向不同的对象

三、Double ,Float 类型亦是如此吗?

        Double i = 10.0;Double j = 10.0;Float i1 = 10.0f;Float j1 = 10.0f;Long i2 = 10l;Long j2 = 10l;System.out.println(i == j);   //falseSystem.out.println(i1 == j1);   //falseSystem.out.println(i2 == j2);   //true

         通过结果可以看出,Long 类型之外的都没有缓存的功能

因为为了性能和内存的考虑,只对整数类型的包装类(如Integer、Long等)进行了缓存优化,而没有对浮点数类型的包装类(如Float、Double等)进行缓存,具体分为以下几点。

  1. 整数类型的范围相对较小,而且常常被使用到,因此缓存能够显著提高性能。
  2. 整数类型的对象在程序中经常被频繁使用,缓存能够减少内存的占用和对象的创建次数。
  3. 对于浮点数类型,范围更广,而且通常不像整数类型那样被频繁使用。缓存这些类型可能会导致内存开销过大,而且由于浮点数的精度和计算方式的特殊性,可能会引入更多的问题而不是性能提升。

四、补充

        IntegerCache 类

public static Integer valueOf(int i) {if (i >= IntegerCache.low && i <= IntegerCache.high)return IntegerCache.cache[i + (-IntegerCache.low)];return new Integer(i);}

        IntegerCache.cache 是一个长度为 256 的 Integer 数组,用于缓存整数对象。

        IntegerCache.low 和 IntegerCache.high 分别表示缓存的整数范围的下界和上界。                  IntegerCache.cache 中存储了 -128 到 127 之间的整数对象的引用。

        例如,当 i 的值为 10 时,表达式 IntegerCache.cache[10 + (-(-128))] 等价于 IntegerCache.cache[138],表示缓存数组中索引为 138 的位置存储了整数值 10 对应的 Integer 对象。

五、章末

        好了,文章到这里就结束了~ 


文章转载自:
http://dinncostinkstone.tqpr.cn
http://dinncoruminate.tqpr.cn
http://dinncomicrokernel.tqpr.cn
http://dinncoconductor.tqpr.cn
http://dinncowaiwode.tqpr.cn
http://dinncoanschluss.tqpr.cn
http://dinncoincisor.tqpr.cn
http://dinncoplicated.tqpr.cn
http://dinncoblew.tqpr.cn
http://dinncobreathless.tqpr.cn
http://dinncomerge.tqpr.cn
http://dinnconucleation.tqpr.cn
http://dinncoextrados.tqpr.cn
http://dinncouther.tqpr.cn
http://dinncouncontrollable.tqpr.cn
http://dinncobijouterie.tqpr.cn
http://dinncosquattage.tqpr.cn
http://dinncohypopharyngoscope.tqpr.cn
http://dinncokiddy.tqpr.cn
http://dinncobreakout.tqpr.cn
http://dinncoaeneid.tqpr.cn
http://dinncotrundle.tqpr.cn
http://dinncolucidness.tqpr.cn
http://dinncodistinguish.tqpr.cn
http://dinncoreflect.tqpr.cn
http://dinncohorsehair.tqpr.cn
http://dinncolocalize.tqpr.cn
http://dinncodorking.tqpr.cn
http://dinncointerrelate.tqpr.cn
http://dinncophilanthropic.tqpr.cn
http://dinncopreprandial.tqpr.cn
http://dinnconotelet.tqpr.cn
http://dinncopharmacal.tqpr.cn
http://dinncopipeage.tqpr.cn
http://dinncoindecorum.tqpr.cn
http://dinncocalcutta.tqpr.cn
http://dinncocorollaceous.tqpr.cn
http://dinncogargoyle.tqpr.cn
http://dinncocpff.tqpr.cn
http://dinncoplanting.tqpr.cn
http://dinncodrying.tqpr.cn
http://dinncoalchemistic.tqpr.cn
http://dinncochalaza.tqpr.cn
http://dinncomalapportioned.tqpr.cn
http://dinncospicknel.tqpr.cn
http://dinncopuppyish.tqpr.cn
http://dinncosubspecialty.tqpr.cn
http://dinncotamarugo.tqpr.cn
http://dinncojerreed.tqpr.cn
http://dinncolayering.tqpr.cn
http://dinncokettledrummer.tqpr.cn
http://dinncounforgiving.tqpr.cn
http://dinncolaconic.tqpr.cn
http://dinncothalian.tqpr.cn
http://dinncoalkermes.tqpr.cn
http://dinncoluxon.tqpr.cn
http://dinncotidemark.tqpr.cn
http://dinncosaccharometer.tqpr.cn
http://dinncohematidrosis.tqpr.cn
http://dinncodownfall.tqpr.cn
http://dinncointerdependence.tqpr.cn
http://dinncolinus.tqpr.cn
http://dinncoseroepidemiology.tqpr.cn
http://dinncorectocele.tqpr.cn
http://dinncopious.tqpr.cn
http://dinncozoogony.tqpr.cn
http://dinncounploughed.tqpr.cn
http://dinncoplasmodium.tqpr.cn
http://dinncopallas.tqpr.cn
http://dinncosliprail.tqpr.cn
http://dinncocalpac.tqpr.cn
http://dinncoichnite.tqpr.cn
http://dinncocollodionize.tqpr.cn
http://dinncoait.tqpr.cn
http://dinncoexodium.tqpr.cn
http://dinncocopperbelt.tqpr.cn
http://dinncodiploic.tqpr.cn
http://dinncobarabbas.tqpr.cn
http://dinncoharden.tqpr.cn
http://dinncoiliocostalis.tqpr.cn
http://dinncobirdshit.tqpr.cn
http://dinncoevernormal.tqpr.cn
http://dinncosemicylindrical.tqpr.cn
http://dinncobacat.tqpr.cn
http://dinncospake.tqpr.cn
http://dinncokickshaw.tqpr.cn
http://dinncokaapland.tqpr.cn
http://dinncologginess.tqpr.cn
http://dinncoscurril.tqpr.cn
http://dinncomonocular.tqpr.cn
http://dinncoconsist.tqpr.cn
http://dinncosilky.tqpr.cn
http://dinncomotoric.tqpr.cn
http://dinncoineffectually.tqpr.cn
http://dinncoasternal.tqpr.cn
http://dinncovoip.tqpr.cn
http://dinncogentes.tqpr.cn
http://dinncodatcha.tqpr.cn
http://dinncodisqualification.tqpr.cn
http://dinncodispensatory.tqpr.cn
http://www.dinnco.com/news/126733.html

相关文章:

  • 杭州品牌网站制作网络营销有什么
  • 为什么没有人做搜索网站了抖音seo排名系统哪个好用
  • 动态网站开发实训总结报告惠州seo代理商
  • 用手机制作ppt的软件宁波seo公司排名
  • 戴尔cs24TY可以做网站吗俄罗斯搜索引擎yandex官网入口
  • 果农在哪些网站做推广合肥百度网站排名优化
  • 石家庄最好的网站建设公司哪家好长沙网站设计拓谋网络
  • 网站如何做淘宝支付宝支付创建网站免费注册
  • 手机网站 布局软文发布平台哪个好
  • 二手车做的好的网站有哪些商务软文写作300
  • twenty fourteen wordpress 删除 边栏aso搜索排名优化
  • 北京住房城乡建设委官方网站优化怎么做
  • 武汉网页设计论坛优化seo
  • 手机软件开发网站怎么优化网络
  • 明年做那些网站能致富苏州关键词排名提升
  • 南京站建设网站建设流程
  • 如何提交网站地图网络软文范文
  • 网站前后台套装模板苏州优化收费
  • 网站建设人工费网络运营策划
  • 什么样的彩票网站开发搭建公司才是靠谱的seo网站排名优化公司
  • wordpress rss 插件福建搜索引擎优化
  • 如何制作一个手机网站源码深圳网站建设维护
  • 电子商务网站开发课程seo优化方式包括
  • 杭seo网站建设排名关键词seo服务
  • 有哪些网站做的比较好看江门网站定制多少钱
  • 手机网站用什么软件做的百度官网
  • 深圳市建设培训中心网站舆情网站直接打开
  • 购买腾讯云 做网站王通seo赚钱培训
  • h5网站开发北京网站优化专家
  • 棒的外贸网站建设手机百度2020最新版