Skip to content

Commit

Permalink
Update Generics.md
Browse files Browse the repository at this point in the history
You messed up the thing you were explaining
  • Loading branch information
matega authored Nov 11, 2024
1 parent 078f7ee commit af6a59a
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ interface Consumer<T> {
consume: (arg: T) => void;
}
```
Then we can use a `Consumer<Animal>` where a `Consumer<Cat>` is expected, because any function that is capable of accepting a `Cat` must also be capable of accepting an `Animal`.
Then we can use a `Consumer<Animal>` where a `Consumer<Cat>` is expected, because any function that is capable of accepting an `Animal` must also be capable of accepting a `Cat`.
This relationship is called *contravariance*: the relationship from `Consumer<T>` to `Consumer<U>` is the same as the relationship from `U` to `T`.
Note the reversal of direction as compared to covariance! This is why contravariance "cancels itself out" but covariance doesn't.

Expand Down

0 comments on commit af6a59a

Please sign in to comment.