groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ibrahim H. (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7582) Closure to SAM coercion doesn't handle overloads with different SAM signatures
Date Wed, 25 Jul 2018 22:47:00 GMT

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

Ibrahim H. commented on GROOVY-7582:
------------------------------------

I thought groovy is smart enough to figure out which interface should be used if the signatures
are different, so even if `Action` has different method like so:
{code:java}
interface Action<T>
{ void exec(T thing, T thing2) }
//...
 c.m{ a,b -> 1 }
{code}
the same error would be thrown, unless explicit coercion is applied:
{code:java}
c.m ({ a,b -> 1 } as Action){code}
I had the same experience with Ratpack as well.

> 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
>            Priority: Major
>
> 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
(v7.6.3#76005)

Mime
View raw message