Define annotation only applicable to static methods
Is there any way to define an annotation in Java that can only be used on static methods? For example, using:
@Reten开发者_Go百科tion(RetentionPolicy.METHOD)
enables you to specify that the annotation can only be used on methods, but what about static methods?
Thanks!
In short, no. But whatever code is processing the annotation can check that the method it's attached to is static.
As far as I was able to tell, there's no annotation for ... annotations that targets specific scopes such as static, etc.
You'd have to validate that programmatically.
精彩评论