Created
July 30, 2019 10:55
-
-
Save ch8n/7a2a5493145a8ecd1b66de748601f74e to your computer and use it in GitHub Desktop.
Destructing non data class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Gotcha #2 non data class destructuring | |
| class Items(val one:Int,val two:Int,val three:Int){ | |
| ... | |
| } | |
| val (o,t,th)= item // create member function component1()...and so on | |
| // manually declare componentN in class | |
| class Items(val one:Int,val two:Int,val three:Int){ | |
| operator fun component1(): Int = one | |
| operator fun component2(): Int = two | |
| operator fun component3(): Int = three | |
| } | |
| val (o,t,th)= item // no error | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment