[問題] xxx = null

看板java作者 (達)時間11年前 (2014/07/19 18:53), 編輯推噓0(004)
留言4則, 4人參與, 最新討論串1/3 (看更多)
問個弱弱的問題 Java很多時候都會出現 XX YYY = null; 例如下面例子 原因是什麼啊 thank public class Main { public static void main(String args[]) { JFrame frame = new JFrame("Welcome"); String picPath = "C:\\xxx.jpg"; Icon icon = new ImageIcon(picPath); JLabel lab = null; JLabel lab = new JLabel("", icon, JLabel.CENTER); 省略 } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.106.192 ※ 文章網址: http://www.ptt.cc/bbs/java/M.1405767188.A.063.html

07/19 18:54, , 1F
compile error 的例子
07/19 18:54, 1F

07/19 20:37, , 2F
寫程式習慣? 不過你這個例子 compile 不會過吧?
07/19 20:37, 2F

07/19 21:46, , 3F
區域變數初始值要給,不過這例子看起來沒啥意義
07/19 21:46, 3F

07/19 23:02, , 4F
duplicate declaration: lab
07/19 23:02, 4F
文章代碼(AID): #1JoauK1Z (java)
討論串 (同標題文章)
以下文章回應了本文
完整討論串 (本文為第 1 之 3 篇):
0
4
文章代碼(AID): #1JoauK1Z (java)