1 package wrapper.demo; 2 3 public class WrapperDemo 4 { 5 6 /** 7 * @param args 8 */ 9 public static void main(String[] args)10 {11 12 // JDK1.5以后,自動(dòng)裝箱,如果裝箱的是一個(gè)字節(jié),那么該數(shù)據(jù)會(huì)被共享,不會(huì)重新開辟新空間13 Integer a = 127; 14 Integer b = 127;15 System.out.PRintln(a == b);//true16 System.out.println(a.equals(b));//true17 18 Integer c = 128; 19 Integer d = 128;20 System.out.println(c == d);//false 21 System.out.println(c.equals(d));//true22 23 Integer x = new Integer(127);24 Integer y = new Integer(127);25 System.out.println(x == y); //false,因?yàn)?=是比較對(duì)象地址,兩個(gè)new,顯然地址不一樣26 System.out.println(x.equals(y));//true,重寫了equals方法,只比較數(shù)值是否相等,顯然相等27 28 }29 30 }新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注