• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic