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

有些话、适合烂在心里 提交于 2021-02-07 14:20:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!