src/org/nutz/lang/reflect/ReflectTool.java
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
        Type type = null;
        GenericDeclaration gd = tv.getGenericDeclaration();

        do {
            type = clazz.getGenericSuperclass();
            if (type == null) {
                return null;
            }
            if (type instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType) type;

                Type rawType = ptype.getRawType();
                boolean eq = gd.equals(rawType) || (gd instanceof Class && rawType instanceof Class && ((Class) gd).isAssignableFrom((Class) rawType));
                if (eq) {
                    TypeVariable<?>[] tvs = gd.getTypeParameters();
                    Type[] types = ptype.getActualTypeArguments();
                    for (int i = 0; i < tvs.length; i++) {
                        if (tv.equals(tvs[i])) {
                            return types[i];
                        }
                    }
                    return null;
                }
            }
            clazz = Lang.getTypeClass(type);
        } while (type != null);
        return null;
    }
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
        Type type = null;
        GenericDeclaration gd = tv.getGenericDeclaration();

        do {
            type = clazz.getGenericSuperclass();
            if (type == null) {
                return null;
            }
            if (type instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType) type;

                Type rawType = ptype.getRawType();
                boolean eq = gd.equals(rawType) || (gd instanceof Class && rawType instanceof Class && ((Class) gd).isAssignableFrom((Class) rawType));
                if (eq) {
                    TypeVariable<?>[] tvs = gd.getTypeParameters();
                    Type[] types = ptype.getActualTypeArguments();
                    for (int i = 0; i < tvs.length; i++) {
                        if (tv.equals(tvs[i])) {
                            return types[i];
                        }
                    }
                    return null;
                }
            }
            clazz = Lang.getTypeClass(type);
        } while (type != null);
        return null;
    }
public static Type getInheritGenericType ( Class < ? > clazz , TypeVariable < ? > tv ) { Type type = null ; GenericDeclaration gd = tv . getGenericDeclaration ( ) ; do { type = clazz . getGenericSuperclass ( ) ; if ( type == null ) { return null ; } if ( type instanceof ParameterizedType ) { ParameterizedType ptype = ( ParameterizedType ) type ; Type rawType = ptype . getRawType ( ) ; boolean eq = gd . equals ( rawType ) || ( gd instanceof Class && rawType instanceof Class && ( ( Class ) gd ) . isAssignableFrom ( ( Class ) rawType ) ) ; if ( eq ) { TypeVariable < ? > [ ] tvs = gd . getTypeParameters ( ) ; Type [ ] types = ptype . getActualTypeArguments ( ) ; for ( int i = 0 ; i < tvs . length ; i ++ ) { if ( tv . equals ( tvs [ i ] ) ) { return types [ i ] ; } } return null ; } } clazz = Lang . getTypeClass ( type ) ; } while ( type != null ) ; return null ; }
获取泛型类clazz中某个TypeVariable对应的真实Type.
@param clazz
@param tv
@return
获取泛型类clazz中某个TypeVariable对应的真实Type .