gpt4 book ai didi

dart - 从函数返回类

转载 作者:行者123 更新时间:2023-12-03 03:42:32 25 4
gpt4 key购买 nike

有人可以解释为什么这行不通吗?

class Foo {
Foo(this.foo);
sayFoo() {
print(foo);
}
}

var test = () => Foo;
test()("blah").sayFoo(); // ERROR

最佳答案

Dart当前不支持构造函数剥离,但计划最终将其添加到该语言中。
test()返回一个Type<Foo>,但是不允许您调用构造函数。

您可以模拟脱落的方法是创建闭合

var test = (String foo) => Foo(foo);
test("blah").sayFoo(); // should work now

关于dart - 从函数返回类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52285494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com