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

as Integer doesn't work with GStringImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.6.5
    • 1.6.6, 1.7-rc-1
    • groovy-jdk
    • None

    Description

      "-1" as Integer
      

      returns -1

      however:

      a = '-1'
      "$a" as Integer
      

      gives

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '-1' with class 'org.codehaus.groovy.runtime.GStringImpl' to class 'java.lang.Integer'
          	at Script1.run(Script1.groovy:2)
      

      But you can do it with:

      a = '-1'
      ( "$a" as String ) as Integer
      

      Tim

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: