Last active
April 22, 2020 19:31
-
-
Save rofrankel/e8b3be77ff5dc0aff4cd28550657b420 to your computer and use it in GitHub Desktop.
Dart generics question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo<T> extends Object { | |
| Foo(this._data); | |
| Foo.construct(this._data); | |
| @override | |
| String toString() => 'my data is $_data'; | |
| final T _data; | |
| } | |
| class NumberFoo extends Foo<num> { | |
| NumberFoo(num data) : super(data); | |
| } | |
| class Bar<T, F extends Foo<T>> { | |
| Bar(this._data); | |
| F makeFoo() => F(_data); | |
| F makeFoo2() => new F(_data); | |
| F makeFoo3() => F.construct(_data); | |
| final T _data; | |
| } | |
| void main() { | |
| for (int i = 0; i < 5; i++) { | |
| Bar<num, NumberFoo> bar; | |
| print(bar.makeFoo()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment