Skip to content

Instantly share code, notes, and snippets.

@evaisse
Last active September 13, 2024 12:01
Show Gist options
  • Save evaisse/9008432862be95ba3ebd60ed26b2432b to your computer and use it in GitHub Desktop.
Save evaisse/9008432862be95ba3ebd60ed26b2432b to your computer and use it in GitHub Desktop.
Show how extends at least `Object` allow to forbid passing dynamic generics
class Generic<T> {
final T that;
Generic(this.that);
}
class TypedGeneric<T extends Object> {
final T that;
TypedGeneric(this.that);
}
void main() {
dynamic a;
Object? b = null;
print((Generic(a)).that.toString());
print(Generic<Object?>(a).that.toString());
print(TypedGeneric(a).that.toString());
print(TypedGeneric(b).that.toString());
print(TypedGeneric("ok").that.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment