public class Test {
interface Parent<T> {
public List<T> get();
}
interface Child extends Parent<String> {
}
public static void main(String[] args) throws Exception {
Method method = Child.class.getMethod("get");
Type type = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[0];
}
}
当我尝试获取使用特定类型的子接口的类型参数时,type结果是T,即使在Child泛型类型中指定为String。如何确定get()子接口上方法的类型?