Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Limitations


For now, you cannot inherit another class when defining a data class. To avoid delaying the 1.0 release, the makers of Kotlin have decided to have this restriction to avoid the problems that would be caused by this. Imagine a data class, Derived, inherits from a data class, Base; if this happens, then these questions need to be answered:

  1. Should an instance of Base be equal to an instance of Derived if they have the same values for all the shared fields?

  2. What if I copy an instance of Derived through a reference of the type Base?

I am sure, in the future, all the limitations will be addressed and we would be able to write code similar to this (the Scala developer would be familiar with the construct of Either):

    sealed abstract class Either<out L, out R> {
      data class Left<out L, out R>(val value: L) : Either<L, R>()
      data class Right<out L, out R>(val value: R) : Either<L, R>()
    }