基本上我對Java很陌生,在理解一條線並使其工作時遇到了問題。Quick Java LinkedList問題
繼承人的代碼行:
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
繼承人的過程及其在:
ClientWorker(Socket client, JTextArea textArea) {
this.client = client;
this.textArea = textArea;
String line = in.readLine();
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
for(int i = 0; i < clients.size(); i++) {
ClientWorker c = clients.get(i);
//The client doesn't need to get it's own data back.
if(c == this){
continue;
}
c.writeString(line);
}
}
它拋出的錯誤是:
SocketThrdServer.java:20: cannot find symbol
symbol : class LinkedList
location: class ClientWorker
LinkedList<ClientWorker> clients = SingletonClients.getClients();
^
SocketThrdServer.java:20: cannot find symbol
symbol : variable
SingletonClients location: class ClientWorker
LinkedList<ClientWorker> clients = SingletonClients.getClients();
沒有人有任何想法如何我可以把它分類?我假設LinkedList被定義爲錯誤,SingletonClients根本沒有被定義,但我不確定在這種情況下如何定義它們?
在此先感謝!
(偏離主題):通過索引循環遍歷LinkedList是非常緩慢的。改爲使用'Iterator'(或新的foreach語法)。 – MAK