Groovy:封闭中的’this’的含义
以下示例改编自“Groovy in Action”
class Mother { Closure birth() { def closure = { caller -> [this,caller] } return closure } } Mother julia = new Mother() closure = julia.birth() context = closure.call(this) println context[0].class.name // Will print the name of the Script class assert context[1] instanceof Script 根据这本书,封闭内部的价值是最外面的范围(即宣布朱利亚的范围).我正确地假设 >这个内部的一个闭包可以评估到关闭的范围吗? 谢谢, 解决方法
看看第144页
对于你的问题
从书中他们说“这是指封闭,而不是声明对象” 无论哪种方式,您的问题的答案仍然是“否”.
恐怕不是. 请注意,Groovy in Action中的第143和144页需要进行一些更正 http://groovy.canoo.com/errata/erratum/show/5 http://groovy.canoo.com/errata/erratum/show/8 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |