Reputation: 613
Can someone explain why this does not work?
class Foo {
Foo(this.foo);
sayFoo() {
print(foo);
}
}
var test = () => Foo;
test()("blah").sayFoo(); // ERROR
Upvotes: 1
Views: 83
Reputation: 657248
Dart currently doesn't support constructor tear-offs, but it's planned to be added to the language eventually.
test()
returns a Type<Foo>
, but that doesn't allow you to invoke the constructor.
What you can do to simulate tear-offs is creating a closure
var test = (String foo) => Foo(foo);
test("blah").sayFoo(); // should work now
Upvotes: 3
Reputation: 44056
It doesn't work because it isn't designed to work that way.
Upvotes: -2