Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8276

`.&` should return `MethodClosure` instead of just `Closure`

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Compiler
    • None

    Description

      if you get method handle using `.&` notation the retrieved object is of type `Closure`. It should be method closure instead. Following code should compile:

          @CompileStatic
          void doSomething(MethodClosure methodClosure) {
              this.doSomething(this.&doSomething)
          }
      

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            musketyr VladimĂ­r OranĂ˝
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: