Using SonarLint IntelliJ 4.5.1.15617
The following code returns java:S1452
. I believe this shouldn’t be reported, as in Collector
, the accumulator type is often hidden as an implementation detail.
Sample code (yes, I know it’s pretty much Collectors.summingInt
, but this applies to all collectors).
import java.util.stream.Collector;
class Scratch {
public static Collector<Integer, ?, Integer> summing() {
return Collector.of(
() -> new int[1],
(a, t) -> a[0] += t,
(a, b) -> {
a[0] += b[0];
return a;
},
a -> a[0]
);
}
}