Trying to filter a collection using a stream, and trying to pass the following lambda to filter() a Set, which gives the arcane error in the title:
unmatchedIncomingFields.stream().filter(s-> s.matches(fieldMatchPattern))
Meanwhile, creating a Predicate object works:
unmatchedIncomingFields.stream().filter(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.matches(fieldMatchPattern);
}
});
According to the JLS, a lambda body is "value-compatible" if every control path returns a value. matches() always gets called and always returns a boolean, so I don't understand what the problem is.
I've also tried all kinds of variations of the same lambda- with and without parentheses and argument types and using expression and block-with-return bodies.
The issue looks to be incorrect, or at least somewhat misleading, error highlighting within IntelliJ, confusing where the actual error was.
The filter occurs within another lambda for a map() operation which I had not specified a return for yet, and for some reason, IntelliJ highlights the inner lambda for the filter, making it look like it is the one with the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With