org.beanfabrics.util
Class GenericsUtil

java.lang.Object
  extended by org.beanfabrics.util.GenericsUtil

public class GenericsUtil
extends java.lang.Object

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:

This class is inspired by Ian Robertson, see http://www.artima.com/weblogs/viewpost.jsp?thread=208860

Author:
Michael Karneim

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
<T> java.util.List<java.lang.reflect.Type>
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

GenericsUtil

public GenericsUtil()
Method Detail

getMethodReturnTypeArguments

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)
Get the actual type arguments a method has used to parameterize it's generic type.

Parameters:
ownerClass -
genericReturnType -
fieldName -
Returns:
a list of the actual type arguments.

getFieldTypeArguments

public 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.

Parameters:
ownerClass -
fieldName -
genericFieldType -
Returns:
a list of the actual type arguments.

getTypeArguments

public static <T> java.util.List<java.lang.reflect.Type> 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.

Parameters:
genericClass - the generic class (or interface)
childClass - the child class
Returns:
a list of the actual type arguments.


© 2010 by Michael Karneim, http://www.beanfabrics.org