mardi 29 octobre 2019

Accessing private default constructor in Java

Say I have class A with a private constructor, and class B that extends it:

public class A {
    private A() {}
}

public class B {
    public B(){
        // error - there is no default constructor available in 'A'
    }
}

I know it is possible to call private constructors via Java Reflection, but how can I do it in the B constructor? Thanks.





Aucun commentaire:

Enregistrer un commentaire