Maven 检查样式错误:“<T>”的预期@param标记

2022-09-04 19:51:21

我有以下通用类型的方法,但是当我运行maven checkstyle(maven-checkstyle-plugin,2.121)时,它在maven构建期间会给我错误消息。我该如何克服这个问题?Expected @param tag for '<T>'

/**
 * 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>

答案 1

它告诉您,您没有为方法类型参数编写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

答案 2

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

像这样:

/**
 * ... 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警告。


推荐