groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vladimír Oraný (JIRA) <>
Subject [jira] [Created] (GROOVY-8276) `.&` should return `MethodClosure` instead of just `Closure`
Date Fri, 04 Aug 2017 10:29:05 GMT
Vladimír Oraný created GROOVY-8276:

             Summary: `.&` should return `MethodClosure` instead of just `Closure`
                 Key: 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:

    void doSomething(MethodClosure methodClosure) {

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 

        if (!(method instanceof MethodClosure)) {
            throw new IllegalArgumentException("Closure must be method closure. Use object.&methodname
to get type safe method closure!")

To achieve similar behavior.

This message was sent by Atlassian JIRA

View raw message