Prottoy Bagchi
Prottoy Bagchi

Reputation: 43

Java - How to find the interfaces extended by a particular interface or the super interface name

Need some help...

I need to find out the interfaces extended by a particular interface or (Super

Interface Name)

Say, I have three interfaces I1, I2, I3. I1 extends I2 and I3. A Class, MyClass extends I1.

Using Reflections in Java, I could get I1 but how to get the interfaces extended by I1 i.e. I2 and I3.

Please send some code to find out the super interface name. i.e. I2 and I3

Thanks in advance...

Upvotes: 1

Views: 1655

Answers (1)

Thomas
Thomas

Reputation: 88707

You can do the same that - as I assume - you're already doing for your class:

I1.class.getInterfaces();

From the JavaDoc:

If this object represents an interface, the array contains objects representing all interfaces extended by the interface.

Just note that this would be the directly extended interfaces, so if I1 extends I2 and I2 extends I3, then you'd have to call that method multiple times.

Upvotes: 2

Related Questions