Case Classes
Immutable data carriers.
What Is a Case Class?
A case class is a special kind of class designed to hold immutable data. You declare it with case class.
Scala generates a lot of useful code for you automatically, making case classes the go-to way to model data.
Declaring One
Just list the fields in the parameter list. Each parameter becomes an immutable field.
No new keyword is required to create an instance.
case class Point(x: Int, y: Int)
object Main {
def main(args: Array[String]): Unit = {
val p = Point(3, 4)
println(p.x)
println(p.y)
}
}