在我看来,这是编译器或JVM中的一个错误,但也许有人有更好的解释.
下面的代码运行正常,但如果我取消注释第二个runnable初始化,直接使用'this',它不能反序列化对象(in.readObject()抛出异常).
public class TestClass implements Serializable {
String msg = "HEY!";
SerializableRunnable runnable;
public TestClass() {
TestClass self = this;
runnable = () -> self.say(); // uses a local copy of 'this'
// runnable = () -> this.say(); // uses 'this' directly
}
public void say() {
System.out.println(msg);
}
public static void main(String[] args) throws Exception {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(buffer)) {
out.writeObject(new TestClass());
}
try (ObjectInputStream in …Run Code Online (Sandbox Code Playgroud) 在了解JSP和servlet时,我听说了重定向和调度.Wicket的setResponsePage()表演中有哪些?