zoukankan      html  css  js  c++  java
  • 参数化

    @Repository
    public class RecommendContentDaoImpl extends MongoDbBaseDaoImpl<RecommendContent> {

    public static void main(String[] args) {
    Class<Object> genricType = getSuperClassGenricType(new RecommendContentDaoImpl().getClass(), 0);
    System.out.println(genricType);
    }

    private static Class<Object> getSuperClassGenricType(final Class clazz, final int index) {
    //返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的直接超类的 Type。
    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
    return Object.class;
    }
    //返回表示此类型实际类型参数的 Type 对象的数组。
    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
    return Object.class;
    }
    if (!(params[index] instanceof Class)) {
    return Object.class;
    }

    return (Class) params[index];
    }

    }

  • 相关阅读:
    4. Object
    3. string
    8. 滚动条美化
    7. 单位,移动布局
    2. js的异步
    2. 即时通讯
    让PHP更快的提供文件下载
    phpstorm+xdebug远程调试设置
    postman自动生成签名
    一位技术人员成长历程
  • 原文地址:https://www.cnblogs.com/gotodsp/p/8855687.html
Copyright © 2011-2022 走看看