gpt4 book ai didi

java - 如何从 Bytebuddy 中的 AnnotationDescription.Loadable 获取注释值

转载 作者:行者123 更新时间:2023-11-30 06:48:44 25 4
gpt4 key购买 nike

我想从特定的注释中获取注释值,例如@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()的参数,我应该做什么?

最佳答案

最简单的解决方案是加载注释,它允许您以类型安全的方式访问值。您可以通过 loadloadSilent 方法执行此操作。或者,您需要提供您想要解析的属性。您可以通过以下方式提供加载的方法引用:MethodDescription.ForLoadedMethod( ... )

关于java - 如何从 Bytebuddy 中的 AnnotationDescription.Loadable 获取注释值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43221668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com