Java 如何从可在Bytebuddy中加载的AnnotationDescription.中获取注释值
我想从一个特定的注释中获取注释值,比如@Callcount,它有一个名为key的字段Java 如何从可在Bytebuddy中加载的AnnotationDescription.中获取注释值,java,byte-buddy,Java,Byte Buddy,我想从一个特定的注释中获取注释值,比如@Callcount,它有一个名为key的字段 MethodList<MethodDescription.InDefinedShape> methods = typeDefinition.getDeclaredMethods(); for (MethodDescription.InDefinedShape method : methods) { AnnotationDescription.Loadable<Call
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?
}
}
MethodList methods=typeDefinition.getDeclaredMethods();
对于(MethodDescription.InDefinedShape方法:方法){
AnnotationDescription.Loadable callCountAnno;
if((callCountAnno=method.getDeclaredAnnotations()。of type(CalledCount.class))!=null){
callCountAnno.getValue(?);//我在这里怎么做?
}
}
我不知道如何构建方法callCountAnno.getValue()的参数,我应该做什么?最简单的解决方案是加载注释,它允许您以类型安全的方式访问值。您可以通过
load
或loadSilent
方法执行此操作。或者,您需要提供要解析的属性。您可以通过:MethodDescription.ForLoadedMethod(…)
提供加载的方法参考,但没有这方面的经验,因此我不想马上给出答案。我刚刚浏览了字节好友的javadocs,看起来参数类型应该是MethodDescription.InDefinedShape
。因此,请尝试getValue(方法)