Created
July 31, 2019 06:44
-
-
Save ch8n/7a8e1720134a4c82a30305b8c3b64e04 to your computer and use it in GitHub Desktop.
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
//initally | |
data class Items(val one: Int, val two: Int, val three: Int) | |
val item = Items(1,2,3) | |
// destructing | |
val (one, two) = item.run { arrayOf(one, two) } // Enforcing position destructing | |
println("$one $two") | |
//after refactor | |
data class Items(val one: Int, val two: Int, val three: Int,val four:Int) | |
val item = Items(1,2,3,4) | |
// no error in destructing for wrong values | |
val (one, two) = item.run { arrayOf(one, two) } // Enforcing position destructing | |
println("$one $two") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment