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

Map-style constructor call, inner class and static compilation

    XMLWordPrintableJSON

Details

    Description

      Consider the following:

      package c 
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class C { 
      	class MyBean { 
      		String foo 
      		int bar 
      	} 
      	class AnotherClass { 
      		int createInt() { 
      			return 1 
      		} 
      		String createString() { 
      			return 'foo' 
      		} 
      	} 
      	
      	void doSomething() { 
      		def a = new AnotherClass() 
      		def b = new MyBean(foo: a.createString()) 
      	} 
      }
      

      The compiler complains on new MyBean(...):

      \src\main\groovy\c\C.groovy: 22: [Static type checking] - Cannot find matching method c.C$MyBean#<init>(c.C, java.util.LinkedHashMap <java.lang.String, java.lang.String>). Please check if the declared type is right and if the method exists.
       @ line 22, column 11.
      

      Changing it to new C.MyBean(...) works though.

      Attachments

        Activity

          People

            emilles Eric Milles
            mauromol Mauro Molinari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: