获取子类传过来的泛型类型

FostDAOImpl<T> extends DAO<T>{
    public void get(){
        //获取子类传过来的泛型类型
        Type genType = this.getClass().getGenericSuperclass();   
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
            for (Type type : params) {
                    System.out.println(type);
            }
    }

}

OrderDAOImpl extends FostDAOImpl<Order>{

    public static void main(String[] args){
        OrderDAOImpl dao =new OrderDAOImpl();
    }
}

你可能感兴趣的:(DAO)