简体   繁体   English

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

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

I am getting checkstyle warnings for missing final modifiers when writing lambdas in Java 8. I want the warnings when writing normal methods, but not in lambdas. 在Java 8中编写lambdas时,我得到了缺少最终修饰符的checkstyle警告。我在编写普通方法时需要警告,但在lambdas中却没有。

For example, summing a list of BigDecimals like this: 例如,将BigDecimals列表汇总如下:

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

gives me the following checkstyle warnings: 给我以下checkstyle警告:

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

Is there a way to make Checkstyle ignore this only when writing lambdas? 有没有办法让Checkstyle在写lambdas时忽略它?

What version of checkstyle are you running. 你正在运行什么版本的checkstyle。 This should have been fixed in version 6.5, so if you are running an earlier version it's a known bug. 这应该已在6.5版本中修复,因此如果您运行的是早期版本,则这是一个已知错误。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM