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

new helper methods to convert Strings into common types (Integer, Long, Float, Double etc)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0-beta-6
    • groovy-jdk
    • None

    Description

      Saw this in code...

      Integer.parseInt(args[0])

      It'd be much more groovy to type

      args[0].toInteger()

      etc

      Or we could use the new 'as' operator to convert to a new type

      args[0] as Integer

      which could be implemented using a generic function

      asType(String self, Class type) {
      switch (type) {
      case Integer:
      return Integer.parse(self)
      }
      ...
      }

      etc

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            jstrachan James Strachan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: