How to read the value of a private field from a different class in Java?

前端 未结 14 1722
梦毁少年i
梦毁少年i 2020-11-21 11:28

I have a poorly designed class in a 3rd-party JAR and I need to access one of its private fields. For example, why should I need to choose priv

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 12:06

    Try FieldUtils from apache commons-lang3:

    FieldUtils.readField(object, fieldName, true);
    

提交回复
热议问题