February 2018
Intermediate to advanced
552 pages
13h 46m
English
Case class is a special kind of class in Scala. In Scala-based applications, we define all our Models or Data Models using Case classes, only because it gives us many benefits for free.
In Scala, we can define a Case class or Case object, using the case keyword:
scala> case class Weather(day:String, temperature:String) defined class Weather
By default, Case class constructors have val parameters, meaning that, we cannot change the values of day and temperature, once they are created.
A Case object is also an object that is defined using the case modifier. When we use a Case object, we will get some benefits for free to avoid boilerplate code.
Here is an example:
scala> case object WeatherAlert defined object WeatherAlert ...
Read now
Unlock full access