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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.6.5
    • Fix Version/s: 1.6.6, 1.7-rc-1
    • Component/s: None
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: