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

Could not call constructor of inner class from anonimous class inside closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.8, 4.0.0-alpha-3, 2.5.16
    • None
    • None

    Description

      When I was trying to call constructor from anonymous class, I catch strange exception

      Could not find matching constructor for: A$B(A$_foo_closure1)
      

      Here is a reproduction

      interface I {
          void bar(Object o)
      }
      class A {
          void foo(){
              C c = new C()
              ['1','2','3'].each {
                  obj ->
                      c.baz(obj, new I() {
                          @Override
                          void bar(Object o) {
                              B b = new B(  )
      
                          }
                      })
              }
          }
          class B {
      
          }
      }
      class C {
          void baz(Object o, I i) {
              i.bar(o)
          }
      }
      A a = new A()
      a.foo()
      

      When my inner class have fields, exception is slightly different

      GroovyRuntimeException: Could not find matching constructor for: A$B(A$_foo_closure1, java.util.LinkedHashMap)
      

      Enviroment : groovy 2.3.9

      Attachments

        Activity

          People

            emilles Eric Milles
            ks.zealot ks.zealot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h