我们不能从Vector<Date> vector = new Vector<Date>()获得Date的类型但是我们可以通过下面的方法获得date的类型
1.写一个方法该方如下合体字
public class ItCastAnnotation {
public static void main(String args[]) {
//2.获得本类的字节码
Class clazz = ItCastAnnotation.class;
//3.获得通过反射获得该类的getType方法对应的Method对象
Method method = clazz.getDeclaredMethod("getType",Vector.class);
//4通过查阅jdk1.5的文档可发下有getGenericParameterTypes()这个方法,获得枚举类型的参数的方法,返回的是一个数组
Type[] type = method.getGenericParameterTypes();
//强制向下类型转换成他的子类
ParameterizedType typeP = (ParameterizedType) type[0];
//5jdk.1.5中getRawTyep()方法获得源类型
System.out.println(typeP.getRawType());
//6getActualTypeArguments()获得类型参数的数组,取第一个打印就会得到Date的类型
System.out.println(typeP.getActualTypeArguments()[0]);
}
private static void getType(Vector<Date> vector) {
}
}