裝箱和拆箱的一個例子

public static void main(String[] args) { Integer t1 = 100; Integer t2 = 100; Integer t3 = 200; Integer t4 = 200; System.out.println((t1 == t2)); System.out.println((t3 == t4)); //使用自動裝箱和自動拆箱的時候 範圍-127 -- 128 的時候比較的值 其它範圍是比較引用 // 爲了避免混淆使用下面方法 Integer t5 = new Integer(100); Integer t6 = new Integer(100); System.out.println((t5 == t6)); }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章