简体   繁体   中英

Java: Is there a way to specificy classes that have a specific annotation?

Okay, so:

Class<? extends YourCustomClass> clazz Class<? extends YourCustomClass> clazz only accepts classes that extend YourCustomClass .
Class<? extends YourCustomInterface> interfaze Class<? extends YourCustomInterface> interfaze only accepts classes that implement YourCustomInterface .

Is there an equivalent for Annotations that does the same thing, because Class<? extends YourCustomAnnotation> annotation Class<? extends YourCustomAnnotation> annotation only accepts annotations that extend YourCustomAnnotation ...

And no, I don't want to filter packages for Annotated classes during code execution, so the Reflections-API won't help.

Thanks for the quick answer!

No , annotations are additional metadata. In a (maven) build one could do an annotation scan So in a post-compilation phase you could check it. With reflection as you mentioned. And did not want. A regex multiline search could find violations.
Joop Eggen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM