今天工作的時(shí)候,幫同事看一個(gè)BUG,突然想到一個(gè)問(wèn)題,大家如果有興趣的話,不妨也想一下答案吧。
以下三段代碼的輸出分別是什么?為什么會(huì)有這樣的結(jié)果?
1 public class BoxingTest {
2
3 public static void main(String[] args) {
4 System.out.println(true ? null : 0);
5 }
6
7 }
1 public class BoxingTest {
2
3 public static void main(String[] args) {
4 System.out.println(true ? (Integer) null : 0);
5 }
6
7 }
1 public class BoxingTest {
2
3 public static void main(String[] args) {
4 System.out.println(true ? (Integer) null : new Integer(0));
5 }
6
7 }
想知道答案的話,自己動(dòng)手試一下吧。:-)
posted on 2009-07-09 20:42
Max 閱讀(6653)
評(píng)論(10) 編輯 收藏 所屬分類:
方法與技巧(Tips & tricks)