From c21dc2e6d931a3eb248300202708c31dd8e995ba Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 4 Jul 2022 20:04:59 +0200 Subject: [PATCH] fix: needs `var` for Dog extends abstract class In the _Dog extends abstract class_ (aka Scala 2 way) `var` keyword is missing in the class defition ``` class Dog(name: String, age: Int) extends Pet(name): ... ``` As a result the `Dog` class fails to compile with the following error `class Dog needs to be abstract, since def age: Int in class Pet is not defined` adding `var` to the definition solves to problem ``` class Dog(name: String, var age: Int) extends Pet(name): ... ``` --- _overviews/scala3-book/domain-modeling-tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_overviews/scala3-book/domain-modeling-tools.md b/_overviews/scala3-book/domain-modeling-tools.md index f69bad4871..0c947c8080 100644 --- a/_overviews/scala3-book/domain-modeling-tools.md +++ b/_overviews/scala3-book/domain-modeling-tools.md @@ -415,7 +415,7 @@ abstract class Pet(name: String): def age: Int override def toString = s"My name is $name, I say $greeting, and I’m $age" -class Dog(name: String, age: Int) extends Pet(name): +class Dog(name: String, var age: Int) extends Pet(name): val greeting = "Woof" val d = Dog("Fido", 1)