What is the point of List.component1 -> 5 functions?
j
Joffrey
09/06/2021, 4:01 PM
These functions are automatically called in destructuring declarations. This allows you to write:
Copy code
val (first, second, third) = myList
Behind the scenes, this will call
myList.component1()
(and 2 and 3) and assign the result to each of these variables.
You will also find such functions automatically generated for data classes.
You can also declare such functions yourself in your own classes if you want.