[ 
https://issues.apache.org/jira/browse/GROOVY-10914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17680252#comment-17680252
 ] 

Eric Milles edited comment on GROOVY-10914 at 1/24/23 3:09 PM:
---------------------------------------------------------------

You can cast at the point of assignment to stop this: "def y = (LongStream) 
...".  This is how I write it to prevent repeating the type when I need to 
short-circuit flow typing.


was (Author: emilles):
You can cast at the point of assignment to stop this: "def y = (LongStream) 
...".  This is how I write it to prevent repeating the type when I need to shut 
down flow typing.

> Method ambiguity error even if the given argument has an explicit type
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-10914
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10914
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>
> I have the following code
> {code}
> import java.util.function.*;
> class Main {
>   static final void test() {
>     String str = "foo"
>     LongConsumer y = str.chars().asLongStream().summaryStatistics();
>     str.chars().asLongStream().summaryStatistics().andThen(y); // Does not 
> work
>     str.chars().asLongStream().summaryStatistics().andThen((LongConsumer) y); 
> // it works
>   }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> Main.groovy: 8: [Static type checking] - Reference to method is ambiguous. 
> Cannot choose between [java.util.function.IntConsumer 
> java.util.function.IntConsumer#andThen(java.util.function.IntConsumer), 
> java.util.function.LongConsumer 
> java.util.function.LongConsumer#andThen(java.util.function.LongConsumer)]
>  @ line 8, column 5.
>        str.chars().asLongStream().summaryStatistics().andThen(y); // Does not 
> work
>        ^
> 1 error
> {code}
> h3. Expected behavior
> Compile successfully
> Tested against master (commit: 5a5726342adeb37a6fbaa8cdcbe2d47dee8dc56c)



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

Reply via email to