Skip to content

Instantly share code, notes, and snippets.

@Midi12
Last active August 15, 2021 18:53
Show Gist options
  • Save Midi12/fc8cacacc833147dd4914e4fe7a6121f to your computer and use it in GitHub Desktop.
Save Midi12/fc8cacacc833147dd4914e4fe7a6121f to your computer and use it in GitHub Desktop.
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