可能吗?
我试过这样的事情:
object foo extends Foo {
constructorNamedArg = "qqq";
} {
abstractMethod() => bar.baz();
}
可能吗?
我试过这样的事情:
object foo extends Foo {
constructorNamedArg = "qqq";
} {
abstractMethod() => bar.baz();
}
I would not use inheritance for this. Instead I would define Foo
as a concrete class:
class Foo(String constructorNamedArg, Baz abstractMethod()) {}
And now at the call site I would write:
Foo {
constructorNamedArg = "qqq";
abstractMethod() => bar.baz();
}
Or even:
Foo {
constructorNamedArg = "qqq";
function abstractMethod() {
return bar.baz();
}
}
It's a common refactoring in Ceylon to go from abstract class with formal methods to concrete class parameterized by functions.
HTH
根据规范,不可能,只能有位置参数列表。