Case objects vs Enumerations in Scala

前端 未结 14 1161
误落风尘
误落风尘 2020-11-22 16:45

Are there any best-practice guidelines on when to use case classes (or case objects) vs extending Enumeration in Scala?

They seem to offer some of the same benefits.

14条回答
  •  一整个雨季
    2020-11-22 17:23

    Another disadvantage of case classes versus Enumerations when you will need to iterate or filter across all instances. This is a built-in capability of Enumeration (and Java enums as well) while case classes don't automatically support such capability.

    In other words: "there's no easy way to get a list of the total set of enumerated values with case classes".

提交回复
热议问题