What are the disadvantages to declaring Scala case classes?

Posted by Graham Lea on Stack Overflow See other posts from Stack Overflow or by Graham Lea
Published on 2011-01-11T01:46:28Z Indexed on 2011/01/11 1:53 UTC
Read the original article Hit count: 502

Filed under:
|
|

If you're writing code that's using lots of beautiful, immutable data structures, case classes appear to be a godsend, giving you all of the following for free with just one keyword:

  • Everything immutable by default
  • Getters automatically defined
  • Decent toString() implementation
  • Compliant equals() and hashCode()
  • Companion object with unapply() method for matching

But what are the disadvantages of defining an immutable data structure as a case class?

What restrictions does it place on the class or its clients?

Are there situations where you should prefer a non-case class?

© Stack Overflow or respective owner

Related posts about scala

Related posts about case-class