You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Cédric Champeau (JIRA)" <ji...@apache.org> on 2015/09/08 08:39:45 UTC

[jira] [Commented] (GROOVY-7582) Closure to SAM coercion doesn't handle overloads with different SAM signatures

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

Cédric Champeau commented on GROOVY-7582:
-----------------------------------------

Agreed. That was out of the scope of the initial implementation (and documented) but we have it in mind (actually we were waiting for such reports to see if it is much trouble).

> Closure to SAM coercion doesn't handle overloads with different SAM signatures
> ------------------------------------------------------------------------------
>
>                 Key: GROOVY-7582
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7582
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.4
>            Reporter: Luke Daley
>
> The following…
> {code}
> interface Action<T> {
>   void exec(T thing)
> }
> interface Block {
>   void exec()
> }
> class Container {
>   void m(Action<?> action) {}
>   void m(Block block) {} 
> }
> def c = new Container()
> c.m { -> 1 }
> {code}
> Yields…
> {code}
> groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method Container#m.
> Cannot resolve which method to invoke for [class ConsoleScript0$_run_closure1] due to overlapping prototypes between:
> 	[interface Action]
> 	[interface Block]
> 	at ConsoleScript0.run(ConsoleScript0:16)
> {code}
> It seems that Groovy should be able to deal with the case where the SAM parameter signatures are different. Java does this with lambda expressions. That is, the following works in Java…
> {code}
> Container c = new Container();
> c.m(() -> {});
> c.m(arg -> {});
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)