As per Scala Doc,
Case classes are good for modeling immutable data.
But that functionality can be achieved by an immutable map too. I'm aware that one can fix the number of keys by specifying the parameter list in case class but apart from this, I wanted to understand in what cases case classes would be a better choice than a map?
Map
is not good for modelling immutable data. - Timname
doingmap("name")
is unsafe and many linters will want you, and doingmap.get("name")
implies you have to deal with an option that you known will be a some always. On the other hand,user.name
is statically proven to be correct. - Luis Miguel Mejía Suárez