1.

What Are The Differences Between Case Class And Normal Class?

Answer»

Case class is also a class, however when we compare it with normal class, it gives the following extra features or benefits:

  • By default, Case-class constructor parameters are ‘val’. We don’t need to declare parameters with ‘val’.
  • By default, Case-class constructor parameters become class fields.
  • These methods are added AUTOMATICALLY: TOSTRING, equals, hashCode, copy. APPLY and unapply.
  • It automatically gets COMPANION object.
  • No need to use ‘new’ keyword to create instance of Case Class.
  • EASY to use in Pattern Matching.

All these features are added by Scala Compiler at compile-time. It is not possible with normal class.

Case class is also a class, however when we compare it with normal class, it gives the following extra features or benefits:

All these features are added by Scala Compiler at compile-time. It is not possible with normal class.



Discussion

No Comment Found