Groovy   发布时间:2022-04-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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

根据这本书,封闭内部的价值是最外面的范围(即宣布朱利亚的范围).我正确地假设

>这个内部的一个闭包可以评估到@L_674_1@的范围吗?
>在上面所示的@L_674_1@中,这个和调用者是否参相同的范围?

谢谢,

解决方法

看看第144页

对于你的问题

从书中他们说“这是指封闭,而不是声明对象”
但是从bertport和我的实验看,“这”实际上是声明对象.

无论哪种方式,您的问题的答案仍然是“否”.

恐怕不是.

请注意,Groovy in Action中的第143和144页需要进行一些更正

http://groovy.canoo.com/errata/erratum/show/5

http://groovy.canoo.com/errata/erratum/show/8

大佬总结

以上是大佬教程为你收集整理的Groovy:封闭中的’this’的含义全部内容,希望文章能够帮你解决Groovy:封闭中的’this’的含义所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。