15.6. Klasy przypadku a dziedziczenie

Nie jest dozwolone tworzenie klasy, ani obiektu przypadku dziedziczących z innej klasy przypadku.

scala> case class J(a: Int)
defined class J

scala> case class K(b: Int, c: Int) extends J(b)
<console>:12: error: case class K has case ancestor J, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes.
       case class K(b: Int, c: Int) extends J(b)
                  ^

scala> case object L extends J(1)
<console>:12: error: case object L has case ancestor J, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes.
       case object L extends J(1)
                   ^

Język programowania Scala Wydanie 2. Copyright © Grzegorz Balcerek 2016

Licencja Creative Commons

Ten utwór jest dostępny na licencji Creative Commons Uznanie autorstwa-Na tych samych warunkach 4.0 Międzynarodowe.

Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.