Source Code : Locates generic declaration by index on a class.

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Locates generic declaration by index on a class.

     
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Util {
  /**
     * Locates generic declaration by index on a class.
     * 
     * @param clazz clazz The class to introspect
     * @param index the Index of the generic ddeclaration,start from 0.
     */
    public static Class getGenericClass(Class clazz, int index) {
      Type genType = clazz.getGenericSuperclass();
      

      if (genType instanceof ParameterizedType) {
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

        if ((params != null) && (params.length >= (index - 1))) {
          return (Class) params[index];
        }
      }
      return null;
    }

}

   
    
    
    
    
  

Thank with us