Skip to content

Instantly share code, notes, and snippets.

@burakemir
Created February 26, 2021 20:55
Show Gist options
  • Save burakemir/83f7f89f5d855bae6708d409f8644904 to your computer and use it in GitHub Desktop.
Save burakemir/83f7f89f5d855bae6708d409f8644904 to your computer and use it in GitHub Desktop.
What happens when you're missing variance
class Foo {}
class Bar extends Foo {}
void main() {
Map<String, Foo> m = {};
Map<String, Bar> n = {};
m = n;
m["a"] = Foo();
// Uncaught Error: TypeError: Instance of 'Foo': type 'Foo' is not a subtype of type 'Bar'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment