简体   繁体   English

groovy.lang.MissingPropertyException:无此类属性:类的所有者:母亲

[英]groovy.lang.MissingPropertyException: No such property: owner for class: Mother

I'm working on the following code: 我正在处理以下代码:

caught exception at 'this.owner' which in the Closure of birth method. 在“关闭出生方法”中的“ this.owner”处捕获到异常。

class Mother {
            int field = 1
            int foo(){
                return 2
            }
            Closure birth(param){
                def local = 3
                def closure = {caller -> [this,field,foo(),local,param,caller,this.owner]} 
                return closure
            }
        }

        Mother m = new Mother();
        closure = m.birth(4);

        context = closure.call(this);
        println context[0].class.name

        assert context[1..4] == [1,2,3,4]
        assert context[5] instanceof Script
        assert context[6] instanceof Mother

        fClosure = m.birth(4);
        sClosure = m.birth(4);
        assert false == fClosure.is(sClosure)

Which, when run finishes with: 当运行完成时:

'this.owner' caught groovy.lang.MissingPropertyException: No such property: owner for class: Mother 'this.owner'捕获到groovy.lang.MissingPropertyException:无此类属性:类的所有者:Mother

Why is that? 这是为什么?

It all works well, please have a look here , especially: 一切正常,请在此处查看 ,特别是:

this corresponds to the enclosing class where the closure is defined this对应于定义闭包的封闭类

Since corresponding class is Mother and it has no owner field nor property defined it fails with MPE. 由于相应的类是Mother ,并且没有owner字段或属性,因此MPE失败。 If you define owner on Mother class it will run (and possibly fail with another exception). 如果您在Mother类上定义owner ,它将运行(并可能因另一个异常而失败)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 groovy.lang.MissingPropertyException:没有这样的属性:类的getTestCaseByName: - groovy.lang.MissingPropertyException: No such property: getTestCaseByName for class: groovy.lang.MissingPropertyException:没有此类属性: - groovy.lang.MissingPropertyException: No such property: 错误:groovy.lang.MissingPropertyException没有这样的属性:sql对于类:Script9 - error: groovy.lang.MissingPropertyException No such property: sql for class: Script9 groovy.lang.MissingPropertyException:没有这样的属性:类的工具包:custom.SampleKeyword - groovy.lang.MissingPropertyException: No such property: Toolkit for class: custom.SampleKeyword groovy.lang.MissingPropertyException:没有这样的属性:任何类:WorkflowScript - groovy.lang.MissingPropertyException: No such property: any for class: WorkflowScript groovy.lang.MissingPropertyException:否这样的属性:类:CustomerCommonRequestBean的getBtnRCR - groovy.lang.MissingPropertyException: No such property: getBtnRCR for class: CustomerCommonRequestBean Jenkins groovy.lang.MissingPropertyException:没有这样的属性:对于类:Script1 - Jenkins groovy.lang.MissingPropertyException: No such property: for class: Script1 Mule Anypoint Studio groovy.lang.MissingPropertyException:没有这样的属性:class 的 StringEscapeUtils - Mule Anypoint Studio groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1 - groovy.lang.MissingPropertyException: No such property: manager for class: Script1 groovy.lang.MissingPropertyException:没有这样的属性:类的列数:Script1 - groovy.lang.MissingPropertyException: No such property: Cols for class: Script1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM