public class TypeArgumentsExtensions extends Object
TypeArgumentsExtensions is a utility class for getting the type arguments a
child class has used to extend a generic base class. It is inspired from the article Reflecting
generics by Ian Robertson at http://www.artima.com/weblogs/viewpost.jsp?thread=208860. In the comments someone asked if
we are allowed to use the source code from the article. The answer of Ian Robertson is:
Absolutely, you may use this code. "Consider it open sourced".| Constructor and Description |
|---|
TypeArgumentsExtensions() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Class<?> |
getFirstTypeArgument(Class<T> baseClass,
Class<? extends T> childClass)
Gets the first type argument from the childClass.
|
static <T> Class<?> |
getTypeArgument(Class<T> baseClass,
Class<? extends T> childClass,
int index)
Gets the type argument from the childClass at the given index or null if it does not exists.
|
static <T> List<Class<?>> |
getTypeArguments(Class<T> baseClass,
Class<? extends T> childClass)
Get the actual type arguments a child class has used to extend a generic base class.
|
public static <T> Class<?> getFirstTypeArgument(Class<T> baseClass, Class<? extends T> childClass)
T - the generic type of the baseClassbaseClass - the base classchildClass - the child classpublic static <T> Class<?> getTypeArgument(Class<T> baseClass, Class<? extends T> childClass, int index)
T - the generic type of the baseClassbaseClass - the base classchildClass - the child classindex - the index of the type argumentpublic static <T> List<Class<?>> getTypeArguments(Class<T> baseClass, Class<? extends T> childClass)
T - the generic type of the baseClassbaseClass - the base classchildClass - the child classCopyright © 2015–2017 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.