我的应用具有以下目录结构:
myapp/
src/
com.me.myapp/
Driver.groovy
Fizz.groovy
stages (package)
AbstractStage.groovy
impl (package)
DefaultStage.groovy
其中:
class Driver {
static void main(String[] args) {
AbstractStage stage1 = new DefaultStage()
stage1.derp
}
}
abstract class AbstractStage {
Set<Fizz> fizzes = new HashSet<Fizz>()
void derp() {
println "I have " + fizzes.size + " attached fizzes!"
}
abstract void doSomething()
}
class DefaultStage extends AbstractStage {
Set<Fizz> executedFizzes = new HashSet<Fizz>()
@Override
void doSomething() {
// TODO: Implement
}
}
当我跑步时,我得到:
Exception in thread "main" groovy.lang.MissingPropertyException: No such property: derp for class:com.me.myapp.stages.impl.DefaultStage
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at com.me.myapp.Driver.main(Driver.groovy:6)
...其中Driver.groovy:6
对应于调用derp
的行。
这里发生了什么?
答案 0 :(得分:2)
derp
是一个方法,而不是属性,所以你需要调用它:
static void main(String[] args) {
AbstractStage stage1 = new DefaultStage()
stage1.derp() // You need the '()' here.
}