OK, Why Would We Use This?

Well, in general, you probably should not use it. It will be rather fragile as classes change. For example, if somebody changes Person to be:

data class Person(
  val name: String,
  val quest: String,
  val favoriteColor: Color,
  val airSpeedVelocityUnladenSwallow: Float
)

Now waitWut winds up being set to the favoriteColor value, not the airSpeedVelocityUnladenSwallow value. In this case, the fact that waitWut becomes a Color instead of a Float means that you might wind up with compiler errors and will detect the fact that waitWut changed. But, if instead Person were changed to:

data class Person(
  val name: String,
  val capitalOfAssyria: String,
  val quest: String,
  val airSpeedVelocityUnladenSwallow: Float
)

Now the value of wait will change, but the type will not, so we might not catch the difference.

(if you do not get the odd references here, go watch this movie, preferably several times)


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.