黑马程序员——通过反射得到函数参数的泛型类

------- <a href="http://www.itheima.com" target="blank">android培训</a>

代码演示:

public class GenericTest {

	public static void main(String[] args) throws Exception{
		
		//通过反射获取的函数的方法
		Method method = GenericTest.class.getMethod("applyVector", Vector.class);
		//得到所以参数的泛型类型
		Type[] types = method.getGenericParameterTypes();
		ParameterizedType pt = (ParameterizedType)types[0];
		System.out.println(pt.getActualTypeArguments()[0]);
		 
	}
	
	public static void applyVector(Vector<Date> v1){
		
	}
}

<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------


猜你喜欢

转载自blog.csdn.net/a1106900429/article/details/40025287