作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从特定的注释中获取注释值,例如@Callcount,它有一个名为key的字段。
MethodList<MethodDescription.InDefinedShape> methods = typeDefinition.getDeclaredMethods();
for (MethodDescription.InDefinedShape method : methods) {
AnnotationDescription.Loadable<CalledCount> callCountAnno;
if ((callCountAnno = method.getDeclaredAnnotations().ofType(CalledCount.class)) != null) {
callCountAnno.getValue(?);//how can i do here?
}
}
我不知道如何构建方法callCountAnno.getValue()的参数,我应该做什么?
最佳答案
最简单的解决方案是加载注释,它允许您以类型安全的方式访问值。您可以通过 load
或 loadSilent
方法执行此操作。或者,您需要提供您想要解析的属性。您可以通过以下方式提供加载的方法引用:MethodDescription.ForLoadedMethod( ... )
。
关于java - 如何从 Bytebuddy 中的 AnnotationDescription.Loadable 获取注释值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43221668/
我想从特定的注释中获取注释值,例如@Callcount,它有一个名为key的字段。 MethodList methods = typeDefinition.getDeclaredMethods();
我是一名优秀的程序员,十分优秀!