- 获取
Method
实例。 - 获取注释。
- 获取注释属性值。
就像是:
Method m = getClass().getMethod("myMethod");MyAnnotation a = m.getAnnotation(MyAnnotation.class);MyValueType value1 = a.attribute1();当然,您需要捕获/处理适当的异常。上述假定您确实是从当前类检索方法(替换
getClass()用
Class.forName()其他方式)和有关方法是公共的(使用
getDeclaredMethods(),如果事实并非如此)



