Multiple annotations of the same type on one element?

前端 未结 8 1300
再見小時候
再見小時候 2020-11-30 21:39

I\'m attempting to slap two or more annotations of the same type on a single element, in this case, a method. Here\'s the approximate code that I\'m working with:

         


        
8条回答
  •  Happy的楠姐
    2020-11-30 22:42

    Two or more annotations of same type aren't allowed. However, you could do something like this:

    public @interface Foos {
        Foo[] value();
    }
    
    @Foos({@Foo(bar="one"), @Foo(bar="two")})
    public void haha() {}
    

    You'll need dedicated handling of Foos annotation in code though.

    btw, I've just used this 2 hours ago to work around the same problem :)

提交回复
热议问题