Reputation: 629
since recently it is possible to create methods with generic methods e.g.:
class Grid2<T> {
static Grid2<T> fromLanes<L, T>(List<L> lanes, T generator(L element, int x, int z)) {
...
}
}
but it would be way nicer to have the same as a named constructor like this (syntax failure) - is this possible?
class Grid2<T>
Grid2.fromLanes<L>(List<L> lanes, T generator(L element, int x, int z)) {
...
}
}
Upvotes: 2
Views: 2348
Reputation: 299
class ArrayList1<T> {
T name;
ArrayList1(T name) {
this.name = name;
}
}
void main() {
ArrayList1<String> obj = new ArrayList1<String>("hello");
print(obj.name);
}
Upvotes: 0
Reputation: 657338
This is currently not supported, but there is an open issue with some discussion
Support generic arguments for (named) constructors https://github.com/dart-lang/sdk/issues/26391
Upvotes: 5