|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.beanfabrics.util.GenericsUtil
public class GenericsUtil
The GenericsUtil is a utility class for accessing generic type
information at runtime.
You can use this class to find out the actual type arguments assigned to a given generic class by a given child class.
Examples:
For the following interface that is a child of the generic interface Collection
public interface StringCollection extends Collection<String> { }
List list = util.getTypeArguments(Collection.class, StringCollection.class);
Class typeArg = (Class)list.get(0);
typeArg will be String.class.
For the following generic interface that is a child of the generic interface Collection
public interface ThrowableCollection<T extends Throwable> extends Collection<T> { }
List list = util.getTypeArguments(Collection.class, ThrowableCollection.class);
TypeVariable typeArg = (TypeVariable)list.get(0);
Type bound = typeArg.getBounds()[0];
bound will be Throwable.class.
| Constructor Summary | |
|---|---|
GenericsUtil()
|
|
| Method Summary | ||
|---|---|---|
static java.util.List<java.lang.reflect.Type> |
getFieldTypeArguments(java.lang.Class<?> ownerClass,
java.lang.String fieldName,
java.lang.Class<?> genericFieldType)
Get the actual type arguments a field has used to parameterize it's generic type. |
|
static java.util.List<java.lang.reflect.Type> |
getMethodReturnTypeArguments(java.lang.Class<?> ownerClass,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Class<?> genericReturnType)
Get the actual type arguments a method has used to parameterize it's generic type. |
|
static
|
getTypeArguments(java.lang.Class<T> genericClass,
java.lang.Class<? extends T> childClass)
Get the actual type arguments a child class has used to extend a generic class. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public GenericsUtil()
| Method Detail |
|---|
public static java.util.List<java.lang.reflect.Type> getMethodReturnTypeArguments(java.lang.Class<?> ownerClass,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Class<?> genericReturnType)
ownerClass - genericReturnType - fieldName -
public static java.util.List<java.lang.reflect.Type> getFieldTypeArguments(java.lang.Class<?> ownerClass,
java.lang.String fieldName,
java.lang.Class<?> genericFieldType)
ownerClass - fieldName - genericFieldType -
public static <T> java.util.List<java.lang.reflect.Type> getTypeArguments(java.lang.Class<T> genericClass,
java.lang.Class<? extends T> childClass)
genericClass - the generic class (or interface)childClass - the child class
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||