是。
Field f = Test.class.getDeclaredField("str"); f.setAccessible(true);//Very important, this allows the setting to work. String value = (String) f.get(object);然后,使用字段对象获取类实例上的值。
请注意,
get方法通常会使人们感到困惑。你有该字段,但没有该对象的实例。你必须将其传递给
get方法

是。
Field f = Test.class.getDeclaredField("str"); f.setAccessible(true);//Very important, this allows the setting to work. String value = (String) f.get(object);然后,使用字段对象获取类实例上的值。
请注意,
get方法通常会使人们感到困惑。你有该字段,但没有该对象的实例。你必须将其传递给
get方法