Java获取泛型参数

 protected DataTableService(){
  this.entityClass = null;
        Class clazz = getClass();
        Type type = clazz.getGenericSuperclass();
        if (type instanceof ParameterizedType) {
            Type[] p = ((ParameterizedType) type).getActualTypeArguments();
            this.entityClass = (Class) p[0];
        }
        if(this.entityClass==null){
         throw new IllegalArgumentException("缺少泛型参数,实体类");
        }
 }

转载于:https://my.oschina.net/xl76832215/blog/502469

你可能感兴趣的:(Java获取泛型参数)