When to use case class or regular class

前端 未结 6 1798
忘掉有多难
忘掉有多难 2020-12-24 10:43

I have some misunderstanding in what cases I should use case class or regular class following by best practices. I have already read about differences of both classes but ca

6条回答
  •  伪装坚强ぢ
    2020-12-24 11:33

    A case class gives you "free" (i.e., you don't have to write) implementations of equals, hashcode and toString, as well as apply and unapply in the companion object. Basically, you can think of a case class as a named tuple, whose fields are named as well.

    For anything else, you're probably better off using a normal class.

提交回复
热议问题