문제

I'm having problems using propertyMissing() together with GroovyShell

I have the files

/**
 * @file FooScript.groovy
 */
abstract class FooScript extends Script {

    def propertyMissing(String name) {
        "This is the property '$name'"
    }

    def propertyMissing(String name, value) {
        println "You tried to set property '$name' to '$value'"
    }
}

and

/**
 * @file FooScriptTest.groovy
 */

import org.codehaus.groovy.control.*


def fooScript = """\
                foo = 'bar'
                println foo"""

def conf = new CompilerConfiguration()
conf.setScriptBaseClass("FooScript")
def sh = new GroovyShell(conf)

sh.evaluate fooScript

When I run FooScriptTest.groovy I expect the output

You tried to set property 'foo' to 'bar'

This is the property 'foo'

What I get is:

bar

Seems my propertyMissing() is overridden by the default one. How do I prevent this?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top