Value of a field of Java object dynamically (by reflection)

Viewed 10650

I get names of various fields in a class like this :

Field[] f = MyClass.class.getDeclaredFields();
Sring str = f[0].toString();
MyClass cl = new MyClass();

Now I want to access the (public) field str from the object cl dynamically. How do I do that?

3 Answers
Related