Hacker News new | ask | show | jobs
by eloisant 974 days ago
It's just a bad example because the dog barking and tree barking just happened to be called the same.

But let's say you have Admin and EndUser that both implement the User class. You would think you could use a []EndUser on a function that takes a []User. Because you can use a EndUser when you need a User.

Except you can't because of mutability. In Scala for example, ListBuffer is invarient (because you could append the wrong type) however the immutable List is covarient so you can call a function that takes a List[User] and pass it a List[EndUser].