Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created July 30, 2019 10:55
Show Gist options
  • Select an option

  • Save ch8n/7a2a5493145a8ecd1b66de748601f74e to your computer and use it in GitHub Desktop.

Select an option

Save ch8n/7a2a5493145a8ecd1b66de748601f74e to your computer and use it in GitHub Desktop.
Destructing non data class
//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