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

"as" and "asType()" produce different results when converting Strings to primitive types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.6.5
    • 1.6.6, 1.7-rc-1
    • None
    • None

    Description

      Try it out:

      println "0" as int
      println "0".asType(int.class)

      I get this output:
      0
      48

      This happens for all the primitives: byte, short, int, long, float, double

      Using the non-primitive types yields the correct result, i.e.:
      println "0" as Integer
      println "0".asType(Integer.class)

      gives:
      0
      0

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            paradoxbomb Ethan Larson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: