最大的差别是在闭包内不使用对象的任何属性,因为它被定义为静态类。
The big difference is that we don't use any properties of the object within the closure, since it is defined as static.
在进行一些灵敏的操作,例如对象导航,特别是使用闭包的时候,Groovy偶尔会遇到歧义性问题和语法受限的问题。
When it came to clever operations such as object navigation, and particularly closures, Groovy suffered from occasional ambiguities and an arguably limiting syntax.
“闭包”可以被看成是在functionscope中的一个临时对象。
The "closure" can be viewed as a temporary object that exists in the function scope.
对象与闭包可以很好地结合使用,比如我们在面向对象的代码内对闭包的特殊处理。
Objects and closures get along very well, as we saw by the special handling of closures within object-oriented code.
由于无需将对象导入闭包中,因此可以节省大量内存,尤其是在拥有许多不需要此功能的闭包时。
By not having to import the object into the closure, we can save quite a bit of memory, especially if we have many closures that don't need this feature.
在类中定义的闭包基本上与在对象外部定义的闭包相同。
Closures defined within a class are fundamentally the same as those defined outside an object.
闭包指“包裹”函数的本地变量,使其在函数外可见及可访问的对象。
"Closes" over the local variables of a function making them visible and accessible outside the function.
闭包指“包裹”函数的本地变量,使其在函数外可见及可访问的对象。
"Closes" over the local variables of a function making them visible and accessible outside the function.
应用推荐