is it possible to use Java Reflection to print out the attributes of a parent class.
Yes, you could do something like this:
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());
}
Given an appropriately permissive security policy, it is possible to print out any class/instance's attributes using reflection. See How to limit setAccessible to only "legitimate" uses? for some interesting discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With