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

Java code behaves wrong on 2.0.5 but not on 1.8.8

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.5
    • 2.1.0-rc-1, 2.0.7
    • primtive opts
    • None
    • Mac

    Description

      The folowing Java code:

      public class HelloWorld {
      	private String[] names;
      	public String[] getNames() { return names; }
      	public void setNames(String... names) { this.names = names; }
      
      	public String toString() {
      		return "Hello " + join(getNames());
      	}
      
      	private String join(String[] strings) {
      		StringBuilder sb = new StringBuilder();
      		String delim = "";
      		for(String string : strings) {
      			sb.append(delim).append(string);
      			delim = ", ";
      		}
      		return sb.toString();
      	}
      
      	public static void main(String[] args) {
      		HelloWorld helloWorld = new HelloWorld();
      		helloWorld.setNames("Morten", "Riccardo", "Anders");
      		System.out.println(helloWorld.toString());
      	}
      }
      

      produces the same output when compiled in Java or in Groovy 1.8.8 (the names joined with commas), but in Groovy 2.0.5 it produces: Hello [Ljava.lang.String;@4e5a67df

      Found while trying to demonstrate how to simplify Java code in Groovy (not very cool...)

      Attachments

        1. GROOVY-5812-test.groovy
          3 kB
          Jan Weitz
        2. StringArrayAccess.groovy
          1 kB
          Jan Weitz

        Activity

          People

            blackdrag Jochen Theodorou
            sbglasius Soeren Glasius
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: