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

static import of multiple methods with same name

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.5
    • None
    • groovy-jdk
    • None

    Description

      Hi,

      Please take a look at this code:

      test.groovy
      import groovy.transform.CompileStatic
      
      import static A1.a // as a1
      import static A2.a // as a2
      import static A3.a // as a3
      
      @CompileStatic
      class A1 {
      	static void a(String str) { println 'a1' }
      }
      
      @CompileStatic
      class A2 {
      	static void a(int i) { println 'a2' }
      }
      
      @CompileStatic
      class A3 {
      	static void a(boolean b) { println 'a3' }
      }
      
      a("string")
      a(1)
      a(true)
      

      Running it, a compile exception is thrown:

      Caught: groovy.lang.MissingMethodException: No signature of method: static A3.a() is applicable for argument types: (java.lang.String) values: [string]
      Possible solutions: a(boolean), any(), any(groovy.lang.Closure), is(java.lang.Object), wait(), wait(long)
      groovy.lang.MissingMethodException: No signature of method: static A3.a() is applicable for argument types: (java.lang.String) values: [string]
      Possible solutions: a(boolean), any(), any(groovy.lang.Closure), is(java.lang.Object), wait(), wait(long)

      It seems that the latest import overwrites the previous ones.
      Is this the expected behavior in Groovy (Java allows this syntax)?

      Best regards,
      Mihai

      Attachments

        Activity

          People

            Unassigned Unassigned
            cazacugmihai Cazacu Mihai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: