gpt4 book ai didi

Java - 获取注释始终为空

转载 作者:行者123 更新时间:2023-11-29 10:10:24 24 4
gpt4 key购买 nike

我是注解的新手,我有一些用自定义注解 FXMLController 进行注解的类,将这些类发送到工厂以从注解中获取值,但它始终为 null ~

注解:

public @interface FXMLController {

String value() default "";

}

用法:

@FXMLController(value=CommonConstants.SPLASH_SCREEN)
public class SplashScreenController{ ....... )

获取值(value):

Annotation annotation = controller.getAnnotation(FXMLController.class);
FXMLController fxmlController = (FXMLController) annotation;

enter image description here

最佳答案

我猜你忘了将注释标记为 @Retention(RetentionPolicy.RUNTIME)

编辑:事实上你的注释应该是这样的:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic @interface FXMLController {
String value() default "";
}

关于Java - 获取注释始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39141134/

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