Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
I have the following program
import java.util.Arrays; class Test { void test() { Double[] x = null; var y = Arrays.stream(x).map(d -> "fda").findFirst(); } }
Actual behavior
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: test.groovy: 7: [Static type checking] - Cannot return value of type java.lang.String for lambda expecting double @ line 7, column 41. y = Arrays.stream(x).map(d -> "fda").fin ^ 1 error
Expected behavior
Compile successfully
This issue stems from the fact that there are two relevant overloaded `stream()` methods in the class `java.utils.Arrays`. See the corresponding signatures below:
- static DoubleStream stream​(double[] array)
- static <T> Stream<T> stream​(T[] array)
So the compiler chooses to call the first method, because it thinks that the first method is more specific than the second one. I don't know if this is a bug or a feature. FYI, javac resolves the second method.
Attachments
Issue Links
- relates to
-
GROOVY-11053 Method ambiguity error when having methods with primitive arrays and varargs
- Closed