Java reflection, get class string array – Education Career Blog

the code is

Field field = st.class.getField("g_"+selectedGroup);

st is my class, and g_+"selectedgroup" is in the st class as String array

how to get that string array?

I need something: String sa= field.getStringArray; but only getInt, getBoolean there is 🙁

how to?


Try this,

Field field = ST.class.getField("g_"+selectedGroup);
String sa = (String)field.get(stInstance);

Where stInstance is an instance of ST class.


You just use get.


If it’s a static field, instance can be null (or really anything).

Leave a Comment