Collection al = new ArrayList(); al.add(1); 因?yàn)榫幾g器會(huì)靜靜的把這段代碼轉(zhuǎn)換成接近這個(gè)樣子:
清單4:作了Autoboxing之后的等價(jià)形式
Collection al = new ArrayList(); al.add(Integer.valueOf(1)); 這里所用的能接受int類(lèi)型的值為參數(shù),生成Integer實(shí)例的valueOf方法,是J2SE 1.5中新加入的內(nèi)容。其它包裹類(lèi)也都有可以接受對(duì)應(yīng)的基本類(lèi)型的值為參數(shù),生成對(duì)應(yīng)的包裹類(lèi)實(shí)例的valueOf方法加入。