Class Inside Class, a Scala language concept

Last updated

A great aspect of Scala is being able to declare classes in other classes. This allows one to reduce repetition and for example refer to values of the outer class effortlessly.

final case class CountryCounter[T](countryMap: Array[Array[T]]) {

  private case class Position(x: Int, y: Int) {
    def valueOf: T = countryMap(y)(x)
  }

}