import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class Main {
public static void main(String[] args) {
try {
Class<?> clazz = Class.forName("MyLibrary$apple");
Field field = clazz.getField("version"); //getDeclaredField 可以调用私有方法
field.setAccessible(true);
System.out.println("field : " + field.get(null));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
public class MyLibrary {
static class apple{
public static String version = "iphone6s[是手机不是吃的苹果]";
}
}