Here you can find the source of getGenericParameterClass(Class clazz)
Parameter | Description |
---|---|
clazz | a parameter |
public static String getGenericParameterClass(Class clazz)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**// w ww. j a va2 s . c om * Gets the first generic between class parents and return's its first parameter type * @param clazz * @return */ public static String getGenericParameterClass(Class clazz) { Type type = clazz.getGenericSuperclass(); while (!(type instanceof ParameterizedType)) { clazz = clazz.getSuperclass(); if (clazz == null) { return null; } type = clazz.getGenericSuperclass(); } String genericTypeName = ((ParameterizedType) type).getActualTypeArguments()[0].getTypeName(); return genericTypeName; } }