jeudi 24 mai 2018

Java Reflection override method in StackPane

How can I override a method in that situation using a reflection? I want to change the return value of methodIWantToChange or override the whole method.

public class PublicClass {
    private ProtectedClass priv;

    public PublicClass() {
        priv = new ProtectedClass();
    }

    protected class ProtectedClass extends StackPane {
        private StackPane pane;

        public ProtectedClass() {
            pane = new StackPane() {
                @Override
                protected double methodIWantToChange(double arg1) {
                return 0;
            }
        }
    }
}

I have tried using Class.forName('PublicClass$ProtectedClass'), then getDeclaredField('pane'), I have set accesible and set to field new StackPane class, but all Ive got is: java.lang.IllegalArgumentException: Can not set javafx.scene.layout.StackPane field PublicClass$ProtectedClass.pane to java.lang.Class





Aucun commentaire:

Enregistrer un commentaire