java.lang.reflect Code Samples
- How do I invoke a method using Method class?
- How do I get field of a class object and set or get its value?
- How do I get fields of a class object?
- How do I get the methods of a class object?
- How do I determine if a class object represents an array class?
- How do I create object using Constructor object?
- How do I get constructors of a class object?
- How do I get modifiers of a class object?
- How do I get the component type of an array?
- How do I get information regarding class name?
- How do I get direct superclass and interfaces of a class?
- How do I check if a class represent a primitive type?
- How do I check if a class represent an interface type?
Page 1 of 1 |
Prev
|
Next
How do I get direct superclass and interfaces of a class?
Java reflection also dealing with inheritance concepts. You can get the direct interfaces and direct superclass of a class by using method getInterfaces() and getSuperclass() of java.lang.Class object.
getInterfaces()will returns an array ofClassobjects that represent the direct super interfaces of the targetClassobjectgetSuperclass()will returns theClassobject representing the direct super class of the targetClassobject ornullif the target representsObjectclass, an interface, a primitive type, or void.
Here is the result of the code snippet:
Direct Interfaces of java.lang.String: java.io.Serializable java.lang.Comparable java.lang.CharSequence Direct Superclass of java.lang.String: is java.lang.Object ==================================== Direct Interfaces of java.util.Date: java.io.Serializable java.lang.Cloneable java.lang.Comparable Direct Superclass of java.util.Date: is java.lang.Object ==================================== Direct Interfaces of javax.swing.JButton: javax.accessibility.Accessible Direct Superclass of javax.swing.JButton: is javax.swing.AbstractButton ==================================== Direct Interfaces of javax.swing.Timer: java.io.Serializable Direct Superclass of javax.swing.Timer: is java.lang.Object ====================================