• Post Reply Bookmark Topic Watch Topic
  • New Topic

Should I use method annotations if I don't access them during runtime?  RSS feed

 
Giedrius Sakalas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. This is a simple example of my case. Suppose I have some method and I pass some arguments to it, it also returns a value. I'm using NetBeans to develope the code. So it automatically generates some annotations for the method according to its signature. This is an example:



So my questions is as the title mentions: should I or should I not use these annotations if I don't access them during the runtime? Is there any point? Maybe the compiler gains some benefit from that?

P.S. Sorry if the question was answered somewhere in the forum before, I wasn't able to get the answer using the forum's search.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those aren't annotations. Those are JavaDoc comments that the javadoc tool uses to generate documentation for your API.

Edit: Welcome to the 'Ranch, by the way!
 
Giedrius Sakalas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I knew this forum is very welcoming

So your answer is "yes, there is a point to keep that"? Are JavaDoc comments used by the compiler or are they only beneficial for the documentation of my code (therefore for the readability, maintainability, etc. of the code)?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's usually a good idea to document (at least) the public API of your classes using Javadoc comments, yes
JavaDoc comments are ignored by the compiler, though you can instruct javac to include them in the binary .class files if you like.
 
Giedrius Sakalas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe I've got the answer I was looking for. Thank you very much
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes well, regarding actual annotations like:


Whether or not these annotations are available at runtime depends on their RetentionPolicy (click for more info).
For example, the Override annotation in the snippet above has a source retention policy, which means it gets dropped by the compiler.
It's only use is to validate - at compile time - that the annotated method does indeed override a method from a super class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!