Skip to content

Instantly share code, notes, and snippets.

@ailabs-software
Created July 25, 2022 17:40
Show Gist options
  • Save ailabs-software/a1be34092b1ddf04bb4b980a69ade05c to your computer and use it in GitHub Desktop.
Save ailabs-software/a1be34092b1ddf04bb4b980a69ade05c to your computer and use it in GitHub Desktop.
More of more specific generic type parameter assigned to variable, causing loss of type checking.
class Foo<T>
{
late T value;
}
void main() {
Foo<Object?> foo1 = new Foo<String>();
Foo<Object?> foo2 = new Foo<int>();
foo1.value = "bar";
foo2.value = "bar"; // Will fail because foo2 is Foo<int>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment