Class GenericTypeExtractor
java.lang.Object
org.mockito.internal.util.reflection.GenericTypeExtractor
Attempts to extract generic type of given target base class or target interface
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> genericTypeOf(Class<?> rootClass, Class<?> targetBaseClass, Class<?> targetBaseInterface) Extract generic type of root class either from the target base class or from target base interface.
-
Method Details
-
genericTypeOf
public static Class<?> genericTypeOf(Class<?> rootClass, Class<?> targetBaseClass, Class<?> targetBaseInterface) Extract generic type of root class either from the target base class or from target base interface. Examples:1. Foo implements IFoo[Integer]: genericTypeOf(Foo.class, Object.class, IFoo.class) returns Integer
2. Foo extends BaseFoo[String]: genericTypeOf(Foo.class, BaseFoo.class, IFoo.class) returns String
3. Foo extends BaseFoo; BaseFoo implements IFoo[String]: genericTypeOf(Foo.class, BaseFoo.class, Object.class) returns String
Does not support nested generics, only supports single type parameter.
- Parameters:
rootClass- - the root class that the search begins fromtargetBaseClass- - if one of the classes in the root class' hierarchy extends this base class it will be used for generic type extractiontargetBaseInterface- - if one of the interfaces in the root class' hierarchy implements this interface it will be used for generic type extraction- Returns:
- generic interface if found, Object.class if not found.
-