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

CompileStatic - Calling vargarg parameter String is converted to array of strings

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.0.2
    • 2.0.4
    • None
    • Windows 7 64bits, JDK 1.7.0_04

    Description

      Assume we have this method:

      static void printMsgs(String ... msgs) {
          for(String s : msgs) { println s;}
      }
      

      Calling it from @CompileStatic:

      @CompileStatic
        static void testCS() {
          //Print:
          // H
          // e
          // l
          // l
          // o
          printMsgs("Hello");
        }
      

      The string 'hello' is converted to array of strings.

      Calling it from non CompileStatic works fines.

      The complete test case:

      public class CompileStaticVarArg {
      
        static void main(String[] args) {
      
      
          test();
      
          println '-' * 20
      
          testCS()
      
        }
      
      
        static void test() {
          // Print 'hello'
          printMsgs("Hello");
        }
      
        @CompileStatic
        static void testCS() {
          //Print:
          // H
          // e
          // l
          // l
          // o
          printMsgs("Hello");
        }
      
        static void printMsgs(String ... msgs) {
      
          for(String s : msgs) {
            println s;
          }
      
        }
      
      }
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            boaznahum Boaz Nahum
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: