一句话概括自动装箱/拆箱
生活随笔
收集整理的這篇文章主要介紹了
一句话概括自动装箱/拆箱
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
自動(dòng)裝箱過(guò)程是通過(guò)調(diào)用包裝類(lèi)的valueOf()方法實(shí)現(xiàn)的,二自動(dòng)拆箱過(guò)程是通過(guò)調(diào)用包裝類(lèi)的xxxValue()方法實(shí)現(xiàn)的(xxx代表對(duì)應(yīng)的基本數(shù)據(jù)類(lèi)型,如intValue,doubleValue等)。
package demo06;public class TestWrapper2 {public static void main(String[] args) {//1.自動(dòng)裝箱和自動(dòng)拆箱Integer in = 5;Integer in2 = new Integer(5);//valueOf()int i = in2;int i2 = in2.intValue();//2.== equalsInteger in3 = new Integer(56);Integer in4 = new Integer(56);System.out.println(in3==in4);//falseSystem.out.println(in3.equals(in4));//trueInteger in5 = 25;Integer in6 = 25;System.out.println(in5==in6);//trueSystem.out.println(in5.equals(in6));//trueInteger in7 = 256;Integer in8 = 256;System.out.println(in7==in8);//falseSystem.out.println(in7.equals(in8));//true} }Integer類(lèi)提供了一個(gè)靜態(tài)內(nèi)部類(lèi)IntegerCache,對(duì)于定義一個(gè)靜態(tài)數(shù)組cache,長(zhǎng)度為256,賦值為-128到127。對(duì)于自動(dòng)裝箱時(shí)如果是-128到127范圍內(nèi)的數(shù)據(jù),
直接獲取數(shù)組的指定值;對(duì)于中國(guó)范圍之外的數(shù)據(jù),通過(guò)new Integer()重新創(chuàng)建對(duì)象,這么做的目的是提高效率。
?
總結(jié)
以上是生活随笔為你收集整理的一句话概括自动装箱/拆箱的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 192.168.8.1手机登陆_高端机型
- 下一篇: mulitpartfile怎么接收不到值