Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kwalrath/edbfbd50121e73d92ae9277bcb4bbe97 to your computer and use it in GitHub Desktop.
Save kwalrath/edbfbd50121e73d92ae9277bcb4bbe97 to your computer and use it in GitHub Desktop.
// Add a contravariant variance modifier
class Writer<in T> {
void write(T x) => print(x);
}
main() {
// Error! Cannot assign Writer<int> to Writer<Object> because the type
// parameter is contravariantly declared.
Writer<Object> objectWriter = new Writer<int>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment