Recommended code style: random Foo object or Foo object extends Serializable?

If I need serialization compatible syntax, do I prefer

case object Foo

or

object Foo extends Serializable

?

+3
source share
1 answer

I think it depends on how you plan to use this object. Case objects are usually used with case classes to represent a source or destination object in an algebraic data type, such as Nilor None. Ordinary objects are usually companions for classes that contain static methods, such as singleton and factory.

, , , , case .

+2

All Articles