Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard way to use JavaDoc to document a Map?

I'm documenting some code, and I have a private HashMap. I'd like to specify information about what is expected from the key and value. Right now I have:

/**
 * HashMap where key=word, value=part of speech
 */
private HashMap<String, String> dictionary;

However, this seems hard to read, and also like it won't work well when I have something more complex like

HashMap<String, HashMap<String, String>>

What are best/common practices for documenting maps?

like image 858
LeahNH Avatar asked Aug 11 '15 14:08

LeahNH


People also ask

How do I document a Javadoc?

From the main menu, select Tools | Generate JavaDoc. In the dialog that opens, select a scope — a set of files or directories for which you want to generate the reference, and set the output directory where the generated documentation will be placed.

What is the format for Javadoc?

The HTML format is used for adding the convenience of being able to hyperlink related documents together. The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, like IntelliJ IDEA, NetBeans and Eclipse, automatically generate Javadoc HTML.

How do you write a good Javadoc?

The correct approach is an @param tag with the parameter name of <T> where T is the type parameter name. There should be one blank line between the Javadoc text and the first @param or @return. This aids readability in source code. The @param and @return should be treated as phrases rather than complete sentences.

What should be included in a Javadoc?

Before using JavaDoc tool, you must include JavaDoc comments /**……………….. */ providing information about classes, methods, and constructors, etc. For creating a good and understandable document API for any java file you must write better comments for every class, method, constructor.


1 Answers

If you need a small javadoc, I suggest the following:

/**
 * Dictionary is a {@link Map} collection that contains {@link Object1} as
 * key and {@link Object2} as value.
 */
private Map<Object1, Object2> dictionary = new HashMap<>();

@link keywork will redirect you on instance definition.

Note : Using an interface as a type (Map instead of HashMap) should be preferred.

like image 184
André Blaszczyk Avatar answered Sep 22 '22 09:09

André Blaszczyk