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

Jochen Theodorou commented on GROOVY-8276:
------------------------------------------

frankly I think returning Closure is the right thing to do here. The same as 
def a = "$x" shouls use GString as type for a and not GStringImpl. It is an 
implementation detail that this Closure is a MethodClosure and unless for good 
reasons I would like to keep it like that. So yes, this would fail static 
compilation.

But maybe if you explain a bit more. Why is it not enough for you to use 
Closure here?

> `.&` should return `MethodClosure` instead of just `Closure`
> ------------------------------------------------------------
>
>                 Key: GROOVY-8276
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8276
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler
>            Reporter: VladimĂ­r OranĂ˝
>
> if you get method handle using `.&` notation the retrieved object is of type 
> `Closure`. It should be method closure instead. Following code should compile:
> {code}
>     @CompileStatic
>     void doSomething(MethodClosure methodClosure) {
>         this.doSomething(this.&doSomething)
>     }
> {code}
> One of the use cases I'm currently working on is a type-safe DSL which 
> accepts method closure to test given method. I would like to be sure that 
> none passes in regular closure. At the moment, I need to do 
> {code}
>         if (!(method instanceof MethodClosure)) {
>             throw new IllegalArgumentException("Closure must be method 
> closure. Use object.&methodname to get type safe method closure!")
>         }
> {code}
> To achieve similar behavior.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to