Java的操作符instanceof的使用和注意點

instanceof操作符是用於java運行時指出對象是否某一特定類的實例.但是用在java的引用數據類型作判斷的時候要注意包裝類的問題,如下:


System.out.println(new Integer(100));


System.out.println(new Integer(100) instanceof Integer);


 /*System.out.println(100 instanceof Integer);*/  //編譯有誤
 /*System.out.println(true instanceof Boolean);*/ //編譯有誤


 System.out.println(new Boolean(true) instanceof Boolean);



發佈了58 篇原創文章 · 獲贊 5 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章