Skip to content

Instantly share code, notes, and snippets.

@kallentu
Last active December 19, 2019 18:33
Show Gist options
  • Save kallentu/c3f09f6bd6e990487e15f0a375931fd7 to your computer and use it in GitHub Desktop.
Save kallentu/c3f09f6bd6e990487e15f0a375931fd7 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() {
// 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