Here you can find the source of getGenericClass(Class clazz)
Parameter | Description |
---|---|
clazz | The class to introspect |
Object.class
if cannot be determined
public static Class getGenericClass(Class clazz)
//package com.java2s; //License from project: Apache License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**/*w w w .j a v a 2 s . c om*/ * get the first generic declaration on a class. * * @param clazz * The class to introspect * @return the first generic declaration, or <code>Object.class</code> if * cannot be determined */ public static Class getGenericClass(Class clazz) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); return (Class) params[0]; } }