是否可能返回另一个const实现?
abstract class Foo<T> {
factory Foo(T thing) => const FooImpl(thing); // <= Arguments of a constant creation must be constant expressions
T get thing;
}
class FooImpl<T> implements Foo<T>{
final T thing;
const FooImpl(this.thing);
}
答案 0 :(得分:4)
Dart有一个委托工厂构造函数来允许这个
abstract class Foo<T> {
const factory Foo(T thing) = FooImpl;
T get thing;
}
class FooImpl<T> implements Foo<T>{
final T thing;
const FooImpl(this.thing);
}
另见
https://groups.google.com/a/dartlang.org/forum/#!topic/misc/cvjjgrwIHbU和 https://groups.google.com/a/dartlang.org/forum/#!topic/misc/cvjjgrwIHbU