I need to extend List
to be able to overload []
operator.
I tried all the approaches from here: How do I extend a List in Dart?. But all of them give me the same error A value of type 'List<dynamic>' can't be assigned to a variable of type 'MyCustomList<int>'.
when I assign usual List
to my extended CustomList:
import 'package:quiver/collection.dart';
class MyCustomList<E> extends DelegatingList<E> {
final List<E> _l = [];
List<E> get delegate => _l;
}
void main() {
MyCustomList<int> l = []; // << error here
}
Is it possible to extend so that this error disappeared?
I know that I can change to:
MyCustomList<int> l = [] as MyCustomList<int>;
But I would like to avoid it because of it would require massive changes in my real code.