• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to force compile time error, if I annotate a method which has void as return type  RSS feed

 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a custom annotation that can be applied on every method at this time. My intention is to limit the use of this annotation and not allow annotation on methods that have void as the return type. In other words, if a method has a return type as void, then I cannot apply my custom annotation on that method. If an attempt is made to apply custom annotation on that method (method that has void as the return type), then raise a compile time error (red X in the IDE).

For example, the name of the custom annotation is MyCustomAnnotation.

In a Java class, I have a method as:
public void myMethod(){....}

If an attempt is made to annotate myMethod, then show a compile time error (red X in the IDE).

How can I force a compile time error, if particular types of methods (all the methods that retun void) are annotated with MyCustomAnnotation?
 
Roberto Perillo
Bartender
Posts: 2273
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Sam!

Well champion, you won't be able to do that. Because this isn't really the target of annotations, which are a simple form of metadata. What you want is something like the @Override, @Deprecated and @SuppressWarnings annotations, which are annotations known by the compiler. I guess that, in order to achieve what you want, you would have to change the compiler so your annotation would be known by it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!