Review

ActiveLecture.org Warm-up exercise: Explain the wildcard in the Collections.fill method.

Scala Generics

Type Bounds

Variance Annotations

Immutable List Example

abstract class List[+T] {
  def isEmpty : Boolean
  def head : T 
  def tail : List[T]
}

case class EmptyList[T]() extends List[T] {
  override def isEmpty : Boolean = true
  override def head = error("No head")
  override def tail = error("No tail")
}

case class NonEmptyList[T](hd : T, tl : List[T]) extends List[T] {
  override def isEmpty : Boolean = false
  override def head = hd
  override def tail = tl
}

Immutable List Example

Positional Safety Checks

Lower Bounds

Conclusion