I can not override methods from Externalizable due to strange weaker access modifier error in java

59 Views Asked by At

In documentation says that readExternal() and writeExternal() have default access modifier and I also implement it with default access modifier, but somehow I have 2 error which says that I assign weaker access modifier? So why is that? (I know that using default modifier I can not serializa/deserialize objects from other package)

Error1:

Error:(19, 10) java: readExternal(java.io.ObjectInput) in A cannot implement readExternal(java.io.ObjectInput) in java.io.Externalizable attempting to assign weaker access privileges; was public

Error2:

Error:(16, 10) java: writeExternal(java.io.ObjectOutput) in A cannot implement writeExternal(java.io.ObjectOutput) in java.io.Externalizable attempting to assign weaker access privileges; was public

class A implements Externalizable
{
    public A() {}
    
    @Override
    void writeExternal(ObjectOutput out) throws IOException {}
    
    @Override
    void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {}
}
0

There are 0 best solutions below