java interface 获取 泛型的真实类型

 default Class<T> thisTClass() {
        Class<?> class1 = getClass();
        Class<?> interfaces = class1.getInterfaces()[0];
        Type[] genericInterfaces = interfaces.getGenericInterfaces();
        Type type = genericInterfaces[0];
        if( type instanceof ParameterizedType ){
            ParameterizedType pType = (ParameterizedType)type;
            Type clazz = pType.getActualTypeArguments()[0];
            if( clazz instanceof Class<?> ){
                return (Class<T>) clazz;
            }
        }
        return null;
    }
原文地址:https://www.cnblogs.com/binz/p/14993266.html