Get parent class and interface
Superclass:
From the Class object you can access the superclass of the class.
Here is how:-
The superclass class object is a Class object like any other, so you can continue doing class reflection on that too.
Class superclass = aClass.getSuperclass();
The superclass class object is a Class object like any other, so you can continue doing class reflection on that too.
Implemented Interfaces:
It is possible to get a list of the interfaces implemented by a given
class. Here is how:-
A class can implement many interfaces. Therefore an array of Class is returned.
Interfaces are also represented by Class objects in Java Reflection.
NOTE: Only the interfaces specifically declared implemented by a given class is returned. If a superclass of the class implements an interface, but the class doesn't specifically state that it also implements that interface, that interface will not be returned in the array. Even if the class in practice implements that interface, because the superclass does.
To get a complete list of the interfaces implemented by a given class you will have to consult both the class and its superclasses recursively.
Class aClass = ... //obtain Class object. See
prev. section Class[] interfaces = aClass.getInterfaces();
A class can implement many interfaces. Therefore an array of Class is returned.
Interfaces are also represented by Class objects in Java Reflection.
NOTE: Only the interfaces specifically declared implemented by a given class is returned. If a superclass of the class implements an interface, but the class doesn't specifically state that it also implements that interface, that interface will not be returned in the array. Even if the class in practice implements that interface, because the superclass does.
To get a complete list of the interfaces implemented by a given class you will have to consult both the class and its superclasses recursively.


