[ 
https://issues.apache.org/jira/browse/GROOVY-10720?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles resolved GROOVY-10720.
----------------------------------
    Resolution: Fixed

https://github.com/apache/groovy/commit/e84c794741f4704df070a0cf8240a4f530ddf676

> Resolving wrong overloaded method?
> ----------------------------------
>
>                 Key: GROOVY-10720
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10720
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>
> I have the following program
> {code}
> import java.util.Arrays;
> class Test {
>     void test() {
>       Double[] x = null;
>       var y = Arrays.stream(x).map(d -> "fda").findFirst();
>     }
> }
> {code}
> h3. Actual behavior
> {code}
> 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
> {code}
> h3. 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to