【问题标题】:Maven checkstyle error : Expected @param tag for '<T>'Maven checkstyle 错误:'<T>' 的预期 @param 标记
【发布时间】:2015-07-25 12:01:59
【问题描述】:

我有以下泛型类型的方法,但是当我运行 maven checkstyle(maven-checkstyle-plugin, 2.121) 时 在 maven 构建期间保持给我Expected @param tag for '&lt;T&gt;' 错误消息。我该如何克服这个问题?

/**
 * Read in specified type of object from request body.
 * @param request The HttpServletRequest
 * @param expected The expected type T
 * @return <T> specified type of object
 */
public <T extends Object> T getExpectedValue(
    final HttpServletRequest request, final Class<T> expected)

我使用以下方法关闭了通用参数标记,但它不起作用,我也提到了上面提到的 java doc。

<module name="JavadocType">
    <property name="allowMissingParamTags" value="true"/>
</module>

【问题讨论】:

  • 你知道这是一个 Javadoc 警告,对吧?它是说你没有用于 T 的 Javadoc。
  • 如果你想关闭 allowMissingParamTags 那么你需要使用 JavadocMethod 模块而不是 JavadocType。文档:checkstyle.sourceforge.net/config_javadoc.html

标签: java maven generics javadoc checkstyle


【解决方案1】:

您将 T 的 @param 标记添加到您的 Javadoc。

类似这样的:

/**
 * ... other comments here ...
 * @param T The expected class of the value.
 * @param request ... other comments here ...
 * @param expected ... other comments here ...
 * @return ... other comments here ...
 */
public <T extends Object> T getExpectedValue(
    final HttpServletRequest request, final Class<T> expected)

如果您没有使用 Javadoc,那么您可能不应该启用 Javadoc 警告。

【讨论】:

  • 你能检查一下我的 java 文档吗?
【解决方案2】:

告诉你方法类型参数没有写javadoc:

/**
 * ...
 * @param <T> This is the type parameter
 * @param ....
 */
 public <T extends Object> T getExpectedValue(
        final HttpServletRequest request, final Class<T> expected)

生成的 javadoc 将在标题中包含如下部分:

Type Parameters: 
    T - This is the type parameter

【讨论】:

  • 但你没有我建议在我的答案中添加的行
  • 我是否需要额外添加您的 java doc 或替换我拥有的一行?你能告诉我哪一行是错的吗?
  • 你没有错行,是加法;它是方法类型参数的文档,它补充了参数和返回的文档(您已经拥有)
  • 您的回答有效。谢谢你。我只是没有足够的点将您的标记为答案。当我有能力时,我会这样做。 :)
猜你喜欢
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 2014-02-22
  • 1970-01-01
  • 2018-08-27
  • 1970-01-01
  • 2020-03-17
  • 1970-01-01
相关资源
最近更新 更多