This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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?
 
Bartender
Posts: 2292
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!