我无法获得字段值.我想要做的是在运行时获取Object.请让我知道我哪里出错了.
的Test.class
import java.lang.reflect.Field;
public class Test {
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
final Field field = Class.forName("com.logging.EX").getDeclaredField("value");
field.setAccessible(true);
field.get(Class.forName("com.logging.EX"));
}
Run Code Online (Sandbox Code Playgroud)
}
EX.class
public class EX {
private String value;
public EX(){
value="data";
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value
* the value to set
*/
public void setValue(String value) {
this.value = value;
}
Run Code Online (Sandbox Code Playgroud)
}