问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/31944539/what-is-the-standard-way-to-use-javadoc-to-document-a-map