理论上使用泛型,在编译时类型就会被擦除掉,那么为什么,
01.package cn.itcast.generic;
02.
03.import java.lang.reflect.Method;
04.import java.lang.reflect.ParameterizedType;
05.import java.lang.reflect.Type;
06.import java.util.Date;
07.import java.util.Vector;
08.
09.public class GenericDemo1 {
10.
11. public static void main(String[] args) throws Exception, NoSuchMethodException {
12.
13. Vector<Date> vector = new Vector<Date>();
14. Method applyMethod = GenericDemo1.class.getMethod("apply", Vector.class);
15. Type[] types = applyMethod.getGenericParameterTypes();
16. ParameterizedType pType = (ParameterizedType) types[0];
17. System.out.println(pType.getRawType());
18. System.out.println(pType.getActualTypeArguments()[0]);
19. }
20.
21. public static void apply(Vector<Date> v) {
22.
23. }
24.}
运行结果为:java.util.Date,
这是为什么呢??大神们给小弟说说你们的理解, |
|