通过委托对象在Groovy中实现抽象类

任何人有关于后续代码块的想法? 尝试实现一个接口或抽象类,而不必手动输入实现。 似乎这个方法methodMissing不完全是诀窍? 可能某种我不知道的授权机制会有帮助?

 class Outer { private List<String> theStrings = [] class Inner implements List<String> { // error because Inner doesn't truly implement List def methodMissing(String name, args) { return getTheStrings().invokeMethod(name, args) } } List<String> getTheStrings() { return theStrings.collect { it.toUpperCase() } } void someOtherMethod() { List<String> blah = new Inner() // warning for incorrect types without the implements } } 

我知道,Groovy并没有真正阻止我将Inner类分配给错误类型的对象,但我更想知道是否有正确的方法来做到这一点。 例如,在Kotlin中,有一个关键字来实现使用委托属性,但我甚至不确定这里适用。