今天工作的時候,幫同事看一個BUG,突然想到一個問題,大家如果有興趣的話,不妨也想一下答案吧。
以下三段代碼的輸出分別是什么?為什么會有這樣的結果?
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 }
想知道答案的話,自己動手試一下吧。:-)
posted on 2009-07-09 20:42
Max 閱讀(6650)
評論(10) 編輯 收藏 所屬分類:
方法與技巧(Tips & tricks)