Groovy web console

subscribe to the feed Subscribe
to this
site
automatic getter access from inside class (via #groovywebconsole)
tweet this snippet Tweet
this
script

automatic getter access from inside class

Published 2 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class MyClass {
    public script

    MyClass(script) {
        this.script = script
    }

    public getResult() {
        return this.script.result
    }

    public setResult(result) {
        this.script.result = result
    }

    public fromInside() {
      println("Inside MyClass: ${this.result}")
    }
}

this.result = null

myobj = new MyClass(this)
myobj.result = 'SUCCESS'

println("Outside MyClass: ${myobj.result}")

myobj.fromInside()