Get value of String variable via reflection
java, reflection
Solution
You need to call:
Object val = f.get(this);
OR to get String object:
String strval = (String) f.get(this);
to get field represented by f's value.
See: `Field#Get(Object)`
Also: `Getting and Setting Field Values`
Problem
I have a POJO with loads of Strings and I want an easy method to check if they are all empty / contain a certain character / whatever. I get the String variables with this: ``` Field[] fields = this.getClass().getDeclaredFields(); for (Field f : fields) { if (f.getType() == java.lang.String.class) { Log.d("REF", "Field: " + f.getName()); } } ``` but I don't know how to get the String value of the Field. How is it done?