class GroovyClass {
def aVariable
void setAVariable(aVariable)
{
this.aVariable = aVariable;
}
}
我的理解是我们不需要在 groovy 类中指定变量的类型。但是如果我声明 'aVariable',Groovy 编译器会抱怨,为什么不将它视为具有默认可访问性的无类型变量?每个变量都应该在 Groovy 中定义 local 和 class 吗?为什么函数定义不必以 def 开头?当我将变量传递给setter时,它不需要任何def吗?