Monday, February 4, 2019

Extending class with private constructor in Serializable class

The document says that a non-serializable supertype needs a no-arg constructor. It does not say it should be private. On the contrary it says this constructor should be accessible. What the documentation means about runtime is this
class A {
    A() {   <-- accessible only in current package
    }
}

public class B extends A implements Serializable {
    public B() {
    }
}

No comments:

Post a Comment