List of usage examples for java.lang Class getGenericSuperclass
public Type getGenericSuperclass()
From source file:Main.java
public static <T> Class<T> getTClass(Class<T> c) { Type genType = c.getGenericSuperclass(); return (Class<T>) ((ParameterizedType) genType).getActualTypeArguments()[0]; }
From source file:Main.java
public static Class getClassGenricType(final Class clazz) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; }/*from w ww . jav a 2 s . c o m*/ Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); return (Class) params[0]; }
From source file:Main.java
public static <T> Class<T> generateType(Class<?> klass) { Type type = klass.getGenericSuperclass(); if (type instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) type; Type[] actualTypes = paramType.getActualTypeArguments(); if (actualTypes != null && actualTypes.length > 0) { return (Class<T>) actualTypes[0]; }// w w w . j a v a 2 s. co m } return null; }
From source file:Main.java
public static <T> Class getClassGenricType(final Class clazz) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; } else {//w ww . j av a 2 s. com Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); return (Class) params[0]; } }
From source file:Util.java
/** * Locates generic declaration by index on a class. * /*from w w w. ja v a2 s . co m*/ * @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; }
From source file:Main.java
@SuppressWarnings("unchecked") public static Class findToken(Class<?> clazz, int tokenIndex) { Type superclass = clazz.getGenericSuperclass(); if (superclass instanceof Class) { throw new RuntimeException("Missing type parameter."); }// w w w. ja v a 2 s .c o m Type entityType = ((ParameterizedType) superclass).getActualTypeArguments()[tokenIndex]; if (!(entityType instanceof Class)) { throw new RuntimeException("Entity type not a class."); } return (Class) entityType; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Class getClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; }//from w w w. j a va2s .c o m Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { return Object.class; } if (!(params[index] instanceof Class)) { return Object.class; } return (Class) params[index]; }
From source file:Main.java
static Class<?> getParametricClass(Class<?> clazz) { ParameterizedType paramType = (ParameterizedType) clazz.getGenericSuperclass(); return getParametricClass(paramType); }
From source file:Main.java
/** * Resgata todos os generics da classe./*from www . ja v a 2 s .c o m*/ * @param clazz Classe generics * @return Generic Type */ public static Class<?>[] getTypeGenericsInstance(Class<?> clazz) { ParameterizedType parameterized = (ParameterizedType) clazz.getGenericSuperclass(); Type[] arguments = parameterized.getActualTypeArguments(); Class<?>[] classes = new Class[arguments.length]; for (int i = 0; i < classes.length; i++) { classes[i] = (Class<?>) arguments[i]; } return classes; }
From source file:Main.java
public static Class<?> getRspClass(Class<?> cbkClass) { try {//w w w. j a v a 2 s . co m java.lang.reflect.Type type = cbkClass.getGenericSuperclass(); if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; Class<?> cls = (Class<?>) parameterizedType.getActualTypeArguments()[0]; return cls; } } catch (Exception e) { e.printStackTrace(); } return null; }