Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
11.2
-
None
-
None
-
OpenJDK 13+33
Description
Consider this code:
private static boolean deepContains( final String needle, final Collection<Collection<String>> haystack) { for (final Collection<String> hay : haystack) { for (final String check : hay) { if (check.equals(needle)) { return true; } } } return false; }
NetBeans suggests to replace the outer loop with with a functional operation, resulting in
private static boolean deepContains( final String needle, final Collection<Collection<String>> haystack) { haystack.forEach((hay) -> { for (final String check : hay) { if (check.equals(needle)) { return true; } } }); return false; }
This does not compile. Error messages:
For the outer loop:
incompatible types: unexpected return value
For the inner loop:
for-each not applicable to expression type
required: array or java.lang.Iterable
found: T
where T is a type-variable:
T extends Object declared in interface Iterable