["首页","博客标签","我","开源","深度学习","机器学习","自然语言","爬虫","编程","开发语言","前端开发","生活","论文","关于me"]
java 反射&泛型相关技巧
作者: IntoHole | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.buyiker.com/2019/08/22/java-reflect-method.html
- 获得继承的接口泛型的类型代码
Type[] types = listener.getClass().getGenericInterfaces();
ParameterizedType parameterized = (ParameterizedType) types[0];
Class<T> clazz = (Class<T>) parameterized.getActualTypeArguments()[0];
- 获得类泛型接口实现
Class<T> tClass = (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];