[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
*
Integer是int的包装类;int是基本数据类型。
*
Integer变量必须实例化后才能使用;int变量不需要。
*
Integer实际是对象的引用,当new一个Integer时,实际上是生成一个指针指向此对象;而int则是直接存储数据值。
*
Integer的默认值是null;int的默认值是0
细细比较,渐入化境:
1、由于Integer变量实际上是对一个Integer对象的引用
,所以两个通过new生成的Integer变量永远是不相等的(因为new生成的是两个对象,其内存地址不同)。
Integer i = newInteger(100); Integer j = newInteger(100); System.out.print(i
== j);//false
2、Integer变量和int变量比较时,只要两个变量的值是向等的,则结果为true(因为包装类Integer和基本数据类型int比较时,
Java会自动拆包装为int,然后进行比较,实际上就变为两个int变量的比较)
Integer i = newInteger(100); int j = 100; System.out.print(i == j);//true
3、非new生成的Integer变量和new Integer()生成的变量比较时,结果为false。(因为
①当变量值在-128~127之间时,非new生成的Integer变量指向的是java常量池中的对象,而new
Integer()生成的变量指向堆中新建的对象,两者在内存中的地址不同)
Integer i = newInteger(100); Integer j = 100; System.out.print(i == j);//false
4、对于两个非new生成的Integer对象,进行比较时,如果两个变量的值在区间-128到127之间
,则比较结果为true,如果两个变量的值不在此区间,则比较结果为false
Integer i = 100; Integer j = 100; System.out.print(i == j);//true Integer i
= 128; Integer j = 128; System.out.print(i == j);//false
对于第4条的原因:
java在编译Integer i = 100 ;时,会翻译成为Integer i = Integer.valueOf(100);,而java
API中对Integer类型的valueOf的定义如下:
public static IntegervalueOf(int i) { assertIntegerCache.high >= 127;
if(i >=IntegerCache.low && i <=IntegerCache.high) {
returnIntegerCache.cache[i +(-IntegerCache.low)]; }
returnnewInteger(i); }