这是代码(简化):
public abstract class PageBase implements Serializable {
private static final long serialVersionUID = -31905358958878336L;
}
public abstract class ListPage extends PageBase {
public Controller getController() {
// Controller is a class
// that implements Serializable and does have an def. constr.
return new Controller() {
@Override
public void someMethod() {
// DoSomething
}
};
}
}
public class ProjectList extends ListPage {
}
通过反序列化它会抛出:
java.io.InvalidClassException: my.pkg.page.ListPage$1; no valid constructor
反序列化发生在 IBM JSF 代码中的某处。
有什么想法吗?谢谢!
最佳答案
my.pkg.page.ListPage$1
将是一个匿名内部类。即使在最好的情况下,序列化嵌套类也不是一个好主意(到完整 JVM 名称的映射很差以及“外部 this”引用的处理)。
该异常看起来好像正在尝试查找派生最多的非Serialized
基类的无参数构造函数,而派生最少的Serialized
基类必须可以访问该构造函数> 类。
关于java - 为什么从抽象 Serialized 继承时会收到 InvalidClassException 'no valid constructor'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3575436/