[問題] 編譯有問題?

看板java作者 (媽!我上電視了)時間15年前 (2010/07/27 14:20), 編輯推噓0(007)
留言7則, 4人參與, 最新討論串1/1
我按照書上程式照著輸入 檢查過沒有打錯字 編譯卻有錯誤 不知道問題出在哪 請高手幫我看看 謝謝 原程式如下: import java.io.*; import java.util.*; public class MatchParenthesis { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in); System.out.println("請輸入一段算式"); System.out.println("->"); String str = br.readLine(); LinkedList match = new LinkedLis(); for(int i=0; i<str.length(); i++) if(str.charAt(i) == '(') match.addFirst(new Charcter('(')); else if(str.charAt(i) == ')') try match.removeFirst(); catch(NoSuchElementException e) { System.out.print("左右括號數量不符, 右括號太少") return; } if(match.isEmpty()) System.out.print("左右括號數量相符"); else System.out.print("左右括號數量不符, 右括號太少") } } 使用javac MatchParenthesis.java 編譯 顯示以下錯誤: Note: MatchParenthesis.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 使用javac MatchParenthesis.java -Xlint 編譯 出現以下錯誤: MatchParenthesis.java:18: warning: [unchecked] unchecked call to addFirst(E) as a member of the raw type java.util.LinkedList match.addFirst(new Character('(')); ^ 1 warning -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.76.60.204 ※ 編輯: gh8811211 來自: 211.76.60.204 (07/27 14:21) ※ 編輯: gh8811211 來自: 211.76.60.204 (07/27 14:22)

07/27 14:26, , 1F
1. 這是 warning 不是 error 2. 你的參考書太舊了
07/27 14:26, 1F

07/27 14:42, , 2F
所以?
07/27 14:42, 2F

07/27 14:43, , 3F
請問要改什麼地方呢
07/27 14:43, 3F

07/27 14:52, , 4F
Generic
07/27 14:52, 4F

07/27 15:01, , 5F
不懂..所以我需要買一本新的書?
07/27 15:01, 5F

07/27 15:04, , 6F
你需要改的部份那本書上沒教,就這樣
07/27 15:04, 6F

07/27 15:16, , 7F
main method 內第一行不是就錯了?
07/27 15:16, 7F
文章代碼(AID): #1CJdhA0u (java)