groovy

Dynamic and static typing

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.0-beta-9
  • Fix Version/s: 1.0-JSR-6
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP
  • Number of attachments :
    0

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}"

Issue Links

Activity

Hide
blackdrag blackdrag added a comment -

the reason for this bug was, that the varibale was stored in the binding, rather than creating a lokal variable. This is now changed and so this will throw an Exception too

Show
blackdrag blackdrag added a comment - the reason for this bug was, that the varibale was stored in the binding, rather than creating a lokal variable. This is now changed and so this will throw an Exception too

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: