java不能同时满足带有参数注释的Checkstyle ModifierOrder和FinalParameters
我正在使用Checkstyle 6.12。我想使用这两个模块:
<module name="ModifierOrder"/>
<module name="FinalParameters"/>
我有一个这样的方法
@GET
@Path("{thingId}")
@Produces(MediaType.TEXT_PLAIN)
public String getThing(
final @PathParam("thingId") String thingId,
) {
return "halp meh";
}
如果对此运行Checkstyle,则会得到如下输出:
<checkstyle version="6.12">
<error line="17" column="13" severity="error"
message="'@PathParam' annotation modifier does not precede non-annotation modifiers."
source="com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck"/>
...
如果去掉final
修饰符,仍然会得到一个错误:
<checkstyle version="6.12">
<error line="17" column="7" severity="error"
message="Parameter version should be final." source="com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck"/>
这种情况让我陷入了尴尬的境地,因为我想用这两种方法在我正在编写的代码上强制使用某种代码样式。有没有办法将Checkstyle配置为在这种情况下工作
# 1 楼答案
正如awks所指出的,在
final
工作之前移动注释我没有注意到这一点的原因是,当我尝试这样做时,我收到了一个编译器错误。问题是我将注释复制了两次: