装箱和拆箱的一个例子

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)); }

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