2 Replies Latest reply on Jan 25, 2014 10:39 PM by matty clown

    Multiple annotations are possible in Events?

    Hwang ar Newbie

      Hello guys,

      I know in Java8 they are working in allow multiple same annotacions can decorate methods or fields (currently is a compiler error)... for instance:

      public void myMethod(@Tag("one") @Tag("another") String param);

       

      In cdi events, using AnnotationLiteral you could declare a string-based qualifier to use in events (there are examples in internet, I simply put its use):

           @Qualfier ... @interface Tag { String value }

           class TagQualifier extends AnnotationLiteral<Tag> implements Tag{ ... }

       

           // Trigger

           beanManager.fireEvent(new CdiEvent(), new TagQualifier("one"));

           // And this will notify in other cdi-enabled class to...   

           void tagListener(@Observes @Tag("one") CdiEvent event) throws Exception { ... }

       

      My question is: providing this is not possible (not compiles):

           void tagListener(@Observes @Tag("one") @Tag("another") CdiEvent event) throws Exception { ... }

       

      ...and the only way to go is to make a multiple annotation like @Tags( { @Tag("one"), @Tag("another") } )

       

      This would match correctly with the observer? Is this supported or planned to be?

       

      Thank you guys!

      Juan Arias