【问题标题】:Will someone kill me if I use <br> in JavaDocs?如果我在 JavaDocs 中使用 <br>,有人会杀了我吗?
【发布时间】:2017-12-23 08:36:29
【问题描述】:

我最近开始使用 Java 进行编码,我经常看到单个 &lt;p&gt; 标记用于分隔行。但就我的目的而言,我实际上并不想制作“段落”,而只是换行,因此阅读文档不会那么糟糕。 &lt;br&gt; 标签可以接受吗?

最后,我想出了 3 种适合该项目的文档样式。我会因为什么被杀?

  • 在代码中看起来不错,但在查看文档时看起来很糟糕

    /**
     * <p> Does highly important adorable things.      </p>
     * <p> Not only helping fields in being suitable
     *     for stack overflowing, but also loves cats. </p>
     * <p> Please do not call while there are
     *     some elephants in the main class.           </p>
     */
    
  • 在代码和文档查看中看起来很糟糕

    /**
     * Does highly important adorable things. <p>
     * Not only helping fields in being suitable
     * for stack overflowing, but also loves cats. <p>
     * Please do not call while there are
     * some elephants in the main class.
     */
    
  • 在代码和文档查看中看起来不错

    /**
     * Does highly important adorable things. <br>
     * Not only helping fields in being suitable
     * for stack overflowing, but also loves cats. <br>
     * Please do not call while there are
     * some elephants in the main class.
     */
    

【问题讨论】:

  • 就个人而言,我会将结果用于解释器而不是代码的最佳输出。但是,P 是一个容器标签,因此您需要

    ...

    。对于 br,我会使用
    。不过,您可以通过在标签周围添加换行符来使其对代码更友好。
  • &lt;pre&gt;&lt;/pre&gt; 有人吗?
  • 不用问队友和用户吗?他们的意见似乎比 SO 更中肯。
  • (再次个人)不太喜欢在整个 javadoc 中使用它。 java.lang.Long#parseLong 很好用
  • 希望

    有一个有效的 html 代码(第一个已关闭)

标签: java comments javadoc


【解决方案1】:

也许更简洁的选项是使用&lt;pre&gt;&lt;/pre&gt;(保持格式):

/**
 * <pre>
 * Does highly important adorable things.
 * Not only helping fields in being suitable
 * for stack overflowing, but also loves cats.
 * Please do not call while there are
 * some elephants in the main class.
 * </pre>
 */

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 2014-04-17
    • 2011-02-20
    • 2021-05-11
    • 1970-01-01
    相关资源
    最近更新 更多