Oh *_*oon 4 java reflection attributes parent
是否可以使用Java Reflection打印出父类的属性.
Whi*_*g34 12
是的,你可以这样做:
Class<?> parentClass = getClass().getSuperclass();
Field[] fields = parentClass.getDeclaredFields();
for (Field field : fields) {
System.out.println("field: " + field.getName());
}
Method[] methods = parentClass.getDeclaredMethods();
for (Method method : methods) {
System.out.println("method: " + method.getName());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3892 次 |
| 最近记录: |