vendredi 22 mars 2019

How to get field value in Java reflection

I have following field in a class:

private String str = "xyz";

How do I get the value xyz using the field name only i.e.

I know the name of the field is str and then get the assigned value. Something like:

this.getClass().getDeclaredField("str").getValue();

Currently the Reflection API has field.get(object).





Aucun commentaire:

Enregistrer un commentaire