Search code examples
javajakarta-eecdi

Java Qualifier With Other Annotations


I would like to write a cdi qualifier which futhermore holds other annotations for instance:

@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
@MyOtherQualifier
public @interface MyQualifier{
    String value();
}

@MyQualifier //MyOtherQualifier is inside too
public void method(){
 //...
}

is there a way to do something like this? its similar to stereotype but not yet same as stereotype. thanks in advance


Solution

  • Short answer: You cannot do that.

    CDI specification does not mandate this, therefore you are sailing undefined waters. The behaviour may vary in each implementation (or perhaps none will allow this).

    You should simply use both annotation which. in the end, might give you a more readable code.

    NOTE: A CDI stereotype does not allow you to specify qualifiers either (except for @Named). Only scope and interceptor bindings.