如何在Groovy中定義一個匿名內部類?我看到了他們應該在Groovy 1.7中支持的參考,並且我使用了1.8。我如何在Groovy中獲得類似匿名內部類的東西?
thread = process.consumeProcessOutput(
new Appendable() {
Appendable append(char c) {
app1.append(c)
app2.append(c)
return this
}
Appendable append(CharSequence csq) {
app1.append(csq)
app2.append(csq)
return this
}
Appendable append(CharSequence csq, int start, int end) {
app1.append(csq, start, end)
app2.append(csq, start, end)
return this
}
})
我得到一個異常與此代碼:
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.UNIXProcess.consumeProcessOutput() is applicable for argument types: (MyClass$1) values: [[email protected]]
以及什麼類型的消耗處理輸出要求?它是Appendable接口嗎? –
描述你的問題的術語被稱爲「封閉」,我認爲... – djangofan
它接受Appendable和OutputStream – dromodel