"which things around case classes will be removed after scala 2.9 exactly?" Code Answer

2

every class in scala must have at least one non-implicit parameter section. if you don't include one, the compiler will add it for you.

scala> class x
defined class x

scala> new x()
res4: x = x@68003589

scala> class y
defined class y

scala> new y()
res5: y = y@467f788b

case classes are no exception. but the interaction with pattern matching is a source of confusion and bugs, which motivates the deprecation.

scala> case class a
<console>:1: warning: case classes without a parameter list have been deprecated;
use either case objects or case classes with `()' as parameter list.
       case class a
                   ^
defined class a

scala> val a = a()
a: a = a()

scala> (a: any) match { case a => 1; case _ => 2 }
res0: int = 2

scala> val companion = a
companion: a.type = a

scala> (companion: any) match { case a => 1; case _ => 2 }
res0: int = 1

as dean suggests, it's usually better to model this with a case object.

i'm not aware of a timeline for removing support for empty-param list case classes. case class inheritance was almost removed in 2.9.0, but that has been deferred until the next major release.

further reading:

why can't the first parameter list of a class be implicit?

By Will Beason on October 5 2022

Answers related to “which things around case classes will be removed after scala 2.9 exactly?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.