How to add reference to a method parameter in Javadoc?
To link to a parameter in Javadoc, use {@code parameterName}
. For example:
By using {@code number}
, we make a connection between number
parameter and its explanation, ensuring comprehensibility in the documentation.
Using different Javadoc tools
Javadoc offers various tools to make your documentation robust, easy-to-read, and comprehensive. Let's dig deeper into them!
How to pick the right tool
Javadoc equips you with different options:
- For mentioning parameters and code snippet,
{@code}
does the job wonderfully. {@link ClassName#methodName}
is your choice for linking to other parts* of the documentation.{@linkplain ClassName#methodName label}
can be useful for referring custom Java elements with a description.{@literal}
comes in handy when you need to include HTML tags within the documentation.
Aesthetics: Making it easy on the eyes
The power of aesthetics is undeniable:
- Compare
{@code Iterator<String>}
with<code><code>Iterator&lt;String&gt;</code></code>
. The former is far more desirable, isn't it? - Consider
{@code paramName}
as a stylish attire for your simple parameter name, bumping up its charm exponentially.
The extra mile: Customization
When you want more than the out-of-the-box documentation:
- Custom doclets allow you to design an exclusive documentation flavor, uniquely catering your project.
- Custom taglets offer your own signature embedded within Javadoc, enabling enriched parameter linking.
Staying in the loop
Remember, Oracle's documentation is your guiding light. Check it regularly for updated practices.
Lessons from popular precedents
Have a sneak peek at open-source libraries for an illustrative use of {@code}
. Follow their lead -- after all, they are the giants in the Java world!
Community consensus
An answer with high votes favoring {@code}
isn't a coincidence! The Java community supports this best practice. Even lesser-voted answers contribute by validating {@code}
’s indispensability in effective documentation.
Catering to edge scenarios
Don’t underestimate the power of catering to the edge scenarios in your documentation. Let's get down to details:
When null strikes
When a parameter can be null
, mention that:
Overloaded methods calling
Differentiate between synonymous methods' parameters. Use {@link}
to make them BFFs:
A matter of formatting
Document parameters expected formats to avoid confusion:
Was this article helpful?