通过反射获取泛型真实类型

try {
            // 通过反射获取T的真是类型
            ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
            Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
            // 通过反射创建model的实例
            model = clazz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

你可能感兴趣的:(通过反射获取泛型真实类型)