java反射
public class Test {
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Person person = new Person();
Class<? extends Person> aClass = person.getClass();
Field name = aClass.getDeclaredField("name");
System.out.println(name.getName());
name.setAccessible(true);
System.out.println(name.getInt(person));
System.out.println(name.get(person).toString());
Field[] declaredFields = aClass.getDeclaredFields();
for (Field declaredField : declaredFields) {
System.out.println(declaredField);
}
System.out.println(aClass.getTypeName());
Method singSong = aClass.getDeclaredMethod("singSong");
singSong.invoke(person);
}
}