void doSomething(@WebParam(name="paramName") int param) { }
Method method = Test.class.getDeclaredMethod("doSomething", int.class);
Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < annotations.length; i ++) {
for (Annotation annotation : annotations[i]) {
System.out.println(annotation);
}
}
此输出:
@javax.jws.WebParam(targetNamespace=, partName=, name=paramName,
header=false, mode=IN)
解释-数组是二维的,因为首先你有一个参数数组,然后对于每个参数你有一个注释数组。
可以使用验证所需注释的类型
instanceof
(或)
Class.isAssignableFrom(..)
.