パラメータにachar
を追加する正しい方法は何ですか?charQueue
final ConcurrentLinkedQueue<Character>
オラクルはそれがうまくいくはずだと言っているようです:
char型からCharacter型へ
http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.7
コード:
package telnet;
import static java.lang.System.out;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;
public class InputStreamWorker {
private final static Logger LOG = Logger.getLogger(InputStreamWorker.class.getName());
public InputStreamWorker() {
}
public void print(final InputStream inputStream, final ConcurrentLinkedQueue<Character> charQueue) {
Thread print = new Thread() {
StringBuilder sb = new StringBuilder();
@Override
public void run() {
try {
char ch = (char) inputStream.read();
sb.append(ch);
while (255 > ch && ch >= 0) {
charQueue.add(ch);
ch = (char) inputStream.read();
System.out.print(ch);
}
} catch (IOException ex) {
out.println("cannot read inputStream:\t" + ex);
}
}
};
print.start();
}
}
ビルド結果からの抜粋:
-do-compile:
[mkdir] Created dir: /home/thufir/NetBeansProjects/TelnetConsole/build/empty
[mkdir] Created dir: /home/thufir/NetBeansProjects/TelnetConsole/build/generated-sources/ap-source-output
[javac] Compiling 11 source files to /home/thufir/NetBeansProjects/TelnetConsole/build/classes
[javac] /home/thufir/NetBeansProjects/TelnetConsole/src/telnet/InputStreamWorker.java:28: error: no suitable method found for add(char)
[javac] charQueue.add(ch);
[javac] ^
[javac] method ConcurrentLinkedQueue.add(Character) is not applicable
[javac] (actual argument char cannot be converted to Character by method invocation conversion)
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error