alvinj / FunctionalProgrammingSimplified

Notes and projects for my book, “Functional Programming, Simplified"
18 stars 2 forks source link

page 480: claim of "case classes don’t allow the use of the new keyword" isn't true #30

Open jim-miller opened 4 years ago

jim-miller commented 4 years ago

Although not idiomatic, case classes can indeed be constructed using new. Subsequently looking for the new keyword is not actually a giveaway that the anonymous class used in the example isn't a case class as claimed on page 480.

e.g., this works just fine:

object Main extends App {
  val p = new Person("Jim", 45)

  println(p)
}

case class Person(name: String, age: Int)