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

Eric Milles edited comment on GROOVY-11094 at 6/13/23 6:56 PM:
---------------------------------------------------------------

You are probably running into the collect extension method "<T> List<T> 
collect(Object self, Closure<T> transform)".

I think you can cast the closure or lambda to {{Supplier}} to force selection 
of the intended overload.


was (Author: emilles):
You are probably running into the collect extension method "<T> List<T> 
collect(Object self, Closure<T> transform)"

> SAM types not working well along with overloading
> -------------------------------------------------
>
>                 Key: GROOVY-11094
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11094
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>              Labels: SAM, overloading
>
> I have the following program:
> {code}
> import java.util.*;
> import java.util.function.*;
> class Bar {
>   LinkedList<String> collect(Supplier<String> function) { }
>         List<String> collect(String x, int y, int z) { }
> }
> class Main {
>   static final void test() {
>     Bar x = null;
>     LinkedList<String> d = x.collect(() -> "fda");
>   }
> }
> {code}
> h3. Actual behaviour
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> test.groovy: 14: [Static type checking] - Cannot assign value of type 
> java.util.List<java.lang.String> to variable of type 
> java.util.LinkedList<java.lang.String>
>  @ line 14, column 28.
>        LinkedList<String> d = x.collect(() -> "fda");
>                               ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> h3. Notes
> Tested against master (commit: cac91791764b8f0b3338318248474412f89e3456)
> Adapted from:
> {code}
> import java.util.*;
> import java.util.function.*;
> import org.eclipse.collections.api.tuple.primitive.BooleanBooleanPair;
> import org.eclipse.collections.api.map.primitive.*;
> import org.eclipse.collections.api.factory.map.primitive.*;
> import org.eclipse.collections.api.collection.*;
> import 
> org.eclipse.collections.api.factory.map.primitive.MutableDoubleFloatMapFactory;
> class Main {
>   static final <G, W>void test() {
>     ImmutableObjectDoubleMap<LongFunction<BooleanBooleanPair>> d = null;
>     final ImmutableCollection<MutableDoubleFloatMapFactory> x = d.collect((p) 
> -> (MutableDoubleFloatMapFactory) null );
>   }
> }
> {code}



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

Reply via email to