How to get value of String field from Java reflection?

后端 未结 3 1904
猫巷女王i
猫巷女王i 2021-01-22 10:21

I have an object that has a String field. I can obtain this field by calling:

Field field = someObj.getClass().getField(\"strField\");

I sett a

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-22 11:20

    if you are using java.lang.reflect.Field, the "setter" is Field.set(Object,Object) and the "getter" is Field.get(Object). in both cases, the first parameter is the instance on which you want to access the field.

提交回复
热议问题