如何禁用 lambda 上缺少最终修饰符的 checkstyle 警告?

How can I disable checkstyle warnings for missing final modifiers on lambdas?

我在 Java 8 中编写 lambda 时收到缺少最终修饰符的 checkstyle 警告。我在编写普通方法时需要警告,但在 lambda 中不需要。

例如,对这样的 BigDecimals 列表求和:

values.stream().reduce(BigDecimal.ZERO, (a, b) -> a.add(b));

给我以下检查样式警告:

- Variable 'a' should be declared final.
- Variable 'b' should be declared final.

有没有办法让 Checkstyle 仅在编写 lambda 时忽略它?

您使用的是哪个版本的 checkstyle 运行。这应该已在 6.5 版中修复,因此如果您是 运行 早期版本,这是一个已知错误。

来源:https://github.com/checkstyle/checkstyle/issues/747