Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions _tour/lower-type-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To fix this, we need to flip the variance of the type of the parameter `elem` in

```tut
trait Node[+B] {
def prepend[U >: B](elem: U)
def prepend[U >: B](elem: U): Node[B]
}
case class ListNode[+B](h: B, t: Node[B]) extends Node[B] {
Expand All @@ -58,13 +58,13 @@ case class Nil[+B]() extends Node[B] {

Now we can do the following:
```tut
trait Mammal
case class AfricanSwallow() extends Mammal
case class EuropeanSwallow() extends Mammal
trait Bird
case class AfricanSwallow() extends Bird
case class EuropeanSwallow() extends Bird
val africanSwallowList= ListNode[AfricanSwallow](AfricanSwallow(), Nil())
val mammalList: Node[Mammal] = africanSwallowList
mammalList.prepend(new EuropeanSwallow)
val birdList: Node[Bird] = africanSwallowList
birdList.prepend(new EuropeanSwallow)
```
The `Node[Mammal]` can be assigned the `africanSwallowList` but then accept `EuropeanSwallow`s.
The `Node[Bird]` can be assigned the `africanSwallowList` but then accept `EuropeanSwallow`s.