What are the disadvantages to declaring Scala case classes?

后端 未结 5 2048

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 o

5条回答
  •  北海茫月
    2020-12-04 06:16

    One big disadvantage: a case classes can't extend a case class. That's the restriction.

    Other advantages you missed, listed for completeness: compliant serialization/deserialization, no need to use "new" keyword to create.

    I prefer non-case classes for objects with mutable state, private state, or no state (e.g. most singleton components). Case classes for pretty much everything else.

提交回复
热议问题