我在使用propertyMissing()
时遇到问题GroovyShell
我有文件
/**
* @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'"
}
}
和
/**
* @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
当我运行时,FooScriptTest.groovy
我期望输出
您试图将属性 'foo' 设置为 'bar'
这是属性'foo'
我得到的是:
酒吧
似乎我propertyMissing()
的被默认覆盖了。我该如何防止这种情况?