Forked from kallentu/variance_motivation_solution.dart
Last active
December 17, 2019 19:28
-
-
Save kwalrath/edbfbd50121e73d92ae9277bcb4bbe97 to your computer and use it in GitHub Desktop.
This file contains 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
// 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