Last active
December 19, 2019 18:33
-
-
Save kallentu/c3f09f6bd6e990487e15f0a375931fd7 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() { | |
// Compile-time error: The constructor returns type 'Writer<int>' | |
// that isn't of expected type 'Writer<Object>'. | |
Writer<Object> objectWriter = Writer<int>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment