package day13;
public class BiseDemo14 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
menthod_2();
}
// 面試題 1.5 新特性
public static void menthod_2()
{
Integer m = 128;
Integer n = 128;
System.out.println("m==n:"+(m==n));//false
Integer a = 127;
Integer b = 127;
System.out.println(a==b);
//結果爲true。因爲a和b指向了同一個Integer對象。
//因爲當數值在byte範圍內容,對於新特性,如果該數值已經存在,
//則不會在開闢新的空間。
}
//1.5新的特性 自動裝箱 拆箱
public static void method_1()
{
Integer x=4; //自動裝箱 new Integer(4)
x=x+2;
/* x進行了自動拆箱 x.intValue()
* 變成了int類型和2進行加法運算
*再將和進行裝箱賦值給x*/
}
}
java1.5 新特性 自動裝箱和拆箱
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.