任何人都可以向我解释为什么如果最终被注释掉,下面的代码可以工作,但如果最终存在则不会?
public class Person { public /*final*/ String firstName,lastName Person(Map parameters) { // This does *not* work with "final": parameters.each { name,value -> this."$name" = value } // This *does* work with "final": this.lastName = parameters['lastName'] } } Person p = new Person(firstName: 'Joe',lastName: 'Doe') println p.firstName + ' ' + p.lastName
换句话说,为什么我在闭包内或构造函数的顶层初始化最终变量有什么不同?