Problems with GroovyShell and propertyMissing()
-
30-10-2019 - |
题
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?
没有正确的解决方案
不隶属于 StackOverflow