From 85d1d474670c0c164dd8c8b8ec7a6a11525a044f Mon Sep 17 00:00:00 2001 From: Sarah Haggarty Date: Wed, 6 Sep 2023 17:36:31 +0200 Subject: [PATCH] chore: clarify covariance example --- docs/topics/generics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/topics/generics.md b/docs/topics/generics.md index 8a9c60ea22c..26cb463ba54 100644 --- a/docs/topics/generics.md +++ b/docs/topics/generics.md @@ -85,7 +85,7 @@ In other words, the wildcard with an _extends_\-bound (_upper_ bound) makes the The key to understanding why this works is rather simple: if you can only _take_ items from a collection, then using a collection of `String`s and reading `Object`s from it is fine. Conversely, if you can only _put_ items into the collection, it's okay to take a collection of `Object`s and put `String`s into it: in Java there is -`List`, a _supertype_ of `List`. +`List`, which accepts `String`s or any of its supertypes. The latter is called _contravariance_, and you can only call methods that take `String` as an argument on `List` (for example, you can call `add(String)` or `set(int, String)`). If you call something that returns `T` in `List`,