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

Dynamic and static typing

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-beta-9
    • 1.0-JSR-6
    • None
    • None
    • Windows XP

    Description

      A statically typed variable in a method cannot be assigned an
      incompatible type. However, the same code works dynamically
      when used outside a method. See following:

      def doSomething() {
      int age = 25
      //age = "youthful" // ERROR: cannot cast 'youthful' to an Integer
      println "Age: ${age}"
      }

      doSomething() // call it

      // do same at outer level
      int age = 25
      age = "youthful" // OK: dynamic typing permitted here
      println "Age: ${age}"

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            blackdrag Jochen Theodorou
            kenb Kenneth Bell
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment