https://kotlinlang.org logo
Title
t

The Monster

09/06/2021, 4:00 PM
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:
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.
t

The Monster

09/06/2021, 4:09 PM
Thanks so much. Why does it stop at 5 though?
because more than 5 destructuring declarations in a statement is code smell?
j

Joffrey

09/06/2021, 4:10 PM
Well, I don't know for sure, but that would be my guess, yes
t

The Monster

09/06/2021, 4:12 PM
oh ok gotcha. Thanks!