ITeye博客

获取泛型转过来的类

java_script · 2012-04-20 17:00 · java编程 · 编程语言 · Markdown

public Class getGenericType(int index) { Type genType = getClass().getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { throw new RuntimeException("Index outof bounds"); } if (!(params[index] instanceof Class)) { return Object.class; } return (Class) params[index]; }

例如:Class<T,E>;T为0索引

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。