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

GString and String do not behave the same when converted to String[]

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.5
    • None
    • None

    Description

      Not sure what "component" implements this behaviour. Tested with JSR-6, but I think it's the same in RC1

      This is my original mail to the list:
      ==================
      groovy> def i= 10
      groovy> def gstr= "hello $i"
      groovy> println "gstr is a GString? ${gstr instanceof GString}"
      groovy> println "gstr is a String? ${gstr instanceof String}"
      groovy> def str= "hello 12"
      groovy> println "str is a GString? ${str instanceof GString}"
      groovy> println "str is a String? ${str instanceof String}"

      gstr is a GString? true
      gstr is a String? false
      str is a GString? false
      str is a String? true

      Now...

      groovy> gstr as String[]
      Result: ["hello 10"]

      However...
      groovy> str as String[]
      Result: ["h", "e", "l", "l", "o", " ", "1", "2"]

      So GString's when converted to String[] produce a one-element array with the whole GString
      But String's when converted to String[] produce an array with one element per character in the String

      (This is Groovy JSR-06)

      BarZ
      =============

      And Graeme Rocher's reply:

      =============
      Hi Barz,

      Please raise an issue, this behaviour is not correct

      Hi Barz,
      =============

      Now, what I don't know: what should the CORRECT BEHAVIOUR be???

      Attachments

        Activity

          People

            Unassigned Unassigned
            barspi Barzilai Spinak
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: