Can I make a Java Annotation which “extends” @SuppressWarnings?

我们两清 提交于 2019-12-10 12:57:16

问题


I know that it's not possible to extends Java annotations.

I've created an annotation for a private field which means that the field is likely to appear unused in the class in which it is declared. For this reason, I'm getting a lot of "unused field" warnings on my annotated fields.

Is there any way to give my annotation the behaviour of @SuppressWarnings("unused") so I don't have to doubly-annotate every field which has @MyAnnotation?


回答1:


The quick answer is "no". Java compiler doesn't know anything about your annotation, so it won't process it the way you want.


But the honest answer is "yes". In this article you can find detailed description of how to write compiler plugin. Chances are you can write plugin, which, in case of finding your annotation, will handle it and won't pass field to unused checker.



来源:https://stackoverflow.com/questions/8680207/can-i-make-a-java-annotation-which-extends-suppresswarnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!