import java.io.*;
import java.net.*;
public class Test {
public static void main(String[] arguments) throws Exception {
Runnable runnable =() -> {
try {
throwException();
}
catch (SocketException|EOFException exception) {
System.err.println("wrong");
}
catch (IOException exception) {
System.err.println("right");
}
};
runnable.run();
}
private static void throwException() throws IOException {
throw new NotSerializableException();
}
}
這個程序爲什麼打印「錯誤」?如果我刪除了lambda,或者如果我拆分多catch子句,那麼它會打印「正確」。組合lambdas和multi-catch子句時出現Java錯誤?
$ javac -version
javac 1.8.0_11
$ java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)