to parameterize

@Repository
public class RecommendContentDaoImpl extends MongoDbBaseDaoImpl<RecommendContent> {

public static void main(String[] args) {
Class<Object> genricType = getSuperClassGenricType(new RecommendContentDaoImpl().getClass(), 0);
System.out.println(genricType) ;
}

private static Class<Object> getSuperClassGenricType(final Class clazz, final int index) {
//Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class.
Type genType = clazz.getGenericSuperclass();

if (!(genType instanceof ParameterizedType)) {
return Object.class;
}
//Returns an array of Type objects representing the actual type parameters of this type.
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];
}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324436564&siteId=291194637