Abdullah Asendar
Abdullah Asendar

Reputation: 604

Java - get annotation is always null

I am new to annotations, i have classes annotated with custom annotation FXMLController, send these classes to a factory to get the value from the annotation, but it is always null ~

annotation :

public @interface FXMLController {

    String value() default "";

}

usage :

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

getting the value :

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

enter image description here

Upvotes: 1

Views: 373

Answers (1)

AlexR
AlexR

Reputation: 115328

I guess that you forgot to mark your annotation as @Retention(RetentionPolicy.RUNTIME)

EDIT: In fact your annotation should look like:

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

Upvotes: 8

Related Questions