I need to determine if a Class object representing an interface extends another interface, ie:
package a.b.c.d;
public Interface IMyInterface extends a.b.d.c.ISomeOtherInterface{
}
according to the spec Class.getSuperClass() will return null for an Interface.
If this Class represents either the Object class, an interface, a primitive type, or void, then null is returned.
Therefore the following won't work.
Class interface = Class.ForName("a.b.c.d.IMyInterface")
Class extendedInterface = interface.getSuperClass();
if(extendedInterface.getName().equals("a.b.d.c.ISomeOtherInterface")){
//do whatever here
}
any ideas?
if (interface.isAssignableFrom(extendedInterface))
is what you want
i always get the ordering backwards at first but recently realized that it's the exact opposite of using instanceof
if (extendedInterfaceA instanceof interfaceB)
is the same thing but you have to have instances of the classes rather than the classes themselves
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