Scala – Case Objects

Case Objects are singleton objects similar to an object with the modifier case. Similar to case classes a lot of boilerplate code is added to when the object is prefixed with the modifer case. Case objects are also serializable as is the case with case classes which is really useful when you are using frameworks like Akka. Defining case objects is simple. See Below Case Objects are quite similar to case classes. They can have members and have some of the same methods like toString, hashCode. Similarly, it is important to understand that some of the methods available in case classes are not available to case objects, for example, apply, unapply. Sealed Case Objects One of the variations of case objects is the sealed case objects. Sealed Case objects are an interesting alternative to the enumeration trait. If you want a peek into scala enumeration trait before diving into sealed case objects, … Read more