Extend data class in Kotlin

后端 未结 8 2016
日久生厌
日久生厌 2020-11-28 04:31

Data classes seem to be the replacement to the old-fashioned POJOs in Java. It is quite expectable that these classes would allow for inheritance, but I can see no convenien

8条回答
  •  感动是毒
    2020-11-28 04:54

    The truth is: data classes do not play too well with inheritance. We are considering prohibiting or severely restricting inheritance of data classes. For example, it's known that there's no way to implement equals() correctly in a hierarchy on non-abstract classes.

    So, all I can offer: don't use inheritance with data classes.

提交回复
热议问题