Last active
August 15, 2021 18:53
-
-
Save Midi12/fc8cacacc833147dd4914e4fe7a6121f to your computer and use it in GitHub Desktop.
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
import 'dart:collection'; | |
class A { | |
A(); | |
} | |
class B extends A { | |
B() : super(); | |
} | |
class Factory { | |
static A build<T extends A>(int some) { | |
if (some == 0) return A(); | |
return B(); | |
} | |
} | |
class CustomList<T extends A> with ListMixin<T> { | |
CustomList(); | |
final List<A> _holder = <A>[]; | |
void populate() { | |
_holder.add(Factory.build<B>(2)); | |
} | |
@override | |
int get length => _holder.length; | |
@override | |
set length(int value) {} | |
@override | |
T operator [](int index) => _holder[index] as T; | |
@override | |
void operator []=(int index, T value) => throw UnimplementedError(); | |
} | |
void main() { | |
final cl = CustomList<B>(); | |
cl.populate(); | |
print(cl[0].runtimeType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment