mardi 24 janvier 2017

How to access protected variable value in child class using reflection in java

Is there anyway to access the value of child class protected variable?

public class Parent{
    protected String protectedValue = "A";
} 

public class Child extends Parent{
    public Child(){
        protectedValue = "B";
    } 
}

I want to access protectedValue set in child class using reflection but its always giving the value from parent class as this field belongs to parent class.





Aucun commentaire:

Enregistrer un commentaire