Difference between case object and object

后端 未结 7 514
梦如初夏
梦如初夏 2020-12-02 04:36

Is there any difference between case object and object in scala?

7条回答
  •  佛祖请我去吃肉
    2020-12-02 04:51

    We know objects and "case class" before. But "case object" is a mix of both i.e it is a singleton similar to an object and with a lot of boilerplate as in a case class. The only difference is that the boilerplate is done for an object instead of a class.

    case objects won't come with the below ones:

    Apply, Un-apply methods. here are no copy methods since this is a singleton. No method for structural equality comparison. No constructor as well.

提交回复
热议问题