1

可能吗?
我试过这样的事情:

object foo extends Foo {
    constructorNamedArg = "qqq";
} {
    abstractMethod() => bar.baz();
}
4

2 回答 2

4

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

于 2015-12-23T11:12:31.570 回答
2

根据规范,不可能,只能有位置参数列表。

于 2015-12-22T11:54:10.503 回答