Can someone explain to me why the code below works if final
commented out, but not if final
present?
public class Person {
public String firstName, lastName
Person(Map parameters) {
parameters.each { name, value ->
this."$name" = value
}
this.lastName = parameters['lastName']
}
}
Person p = new Person(firstName: 'Joe', lastName: 'Doe')
println p.firstName + ' ' + p.lastName
In other words, why is the difference whether I initialize the final variable inside the closure or at the top level of the constructor?
source
share