Alex
Alex

Reputation: 11579

Find interfaces defined in the class

How to find all available interfaces defined in the class using Apache BeanUtils, MethodUtils etc. ?

public class MyClass() {
   .....
   public interface Interface1{};
   public interface Interface2{};
}

Upvotes: 1

Views: 65

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500225

I suspect you just want Class.getClasses():

Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. This includes public class and interface members inherited from superclasses and public class and interface members declared by the class. This method returns an array of length 0 if this Class object has no public member classes or interfaces. This method also returns an array of length 0 if this Class object represents a primitive type, an array class, or void.

So call MyClass.class.getClasses(), and then filter out non-interfaces using Class.isInterface.

Upvotes: 5

Related Questions