By default, the Scala compiler adds the following benefits to a Case class for free:
- The toString, hashCode, and equals methods. When we use the case keyword, the Scala compiler adds these methods for free to avoid boilerplate code.
- A companion object with apply and unapply methods, that's why there is no need to use new keywords to create instances of a Case classes copy method.
- Easy to use in pattern matching. It is immutable because, by default, its constructor parameters are val.
In Scala, by default, case class and case objects are serializable.