JDK1.5版本以後出現的新特性

/*
JDK1.5版本以後出現的新特性。
*/
class IntegerDemoxin
{
public static void main(String[] args) 
{
// Integer x=4;//自動裝箱。//new Integer(4)
// x=x+2;//x=2:x進行自動拆箱,變成int類型,和2進行加法運算。再將和進行裝箱付給x


Integer m=128;
Integer n=128;
sop("m==n"+(m==n));
Integer a=127;
Integer b=127;
sop("a==b"+(a==b));//結果爲true,因爲a和b指向了同一個Integer對象。因爲當數值
//在byte範圍內,對於新特性,如果該數值已經存在,不會再開闢新的空間、
//Integer x= new Integer("123");


//Integer y= new Integer(123);


//sop("x==y:"+(x==y));
//sop("x.equals(y):"+x.equals(y));
 
}
public static void sop(String str)
{
System.out.println(str);
}

}
發佈了16 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章