Data classes and inheritance

Currently, the proposal is to drop the following inheritance cases:

  • A data class extends a regular class
  • A regular class extends a data class
  • A data class extends another data class

Allowing for any of the preceding cases would violate the contract of a data class being a carrier of data. At present, the following restrictions are proposed for data classes and inheritance, with interfaces and abstract data classes:

  • Non-abstract and abstract data classes can extend other abstract data classes
  • An abstract or non-abstract data class can extend any interface

The following figure sums up these inheritance rules:

Let's get started by extending an abstract data class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.97.40