Scala case object

This one should be pretty quick.

Introducing case object.

There is not much to it at first sight. It is the equivalent of what case class is for class but for object.

A case object has everything a object have. Feel free to go back to the corresponding episode. But add also some convenient method. For instance the `toString is a lot nicer, allowing you to get the name of the case object itself which allow for great logging.

It was not easy to introduce only case object because their main use case is in the implementation of the Scala v2.x Enumerations which we are going to see next time. I wanted a dedicated episode to Enumeration but couldn't go for it until case object were introduced. Now that it is done, see you next time.

Reveal more information and clues
Load Exercise