Last active
June 1, 2019 16:31
-
-
Save christianb/2474bac997ef21812afefb2d12b7723d to your computer and use it in GitHub Desktop.
Carfefull with destructuring declaration
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
// A problem like destructuring declarations | |
// by Maria Neumayer | |
// https://medium.com/a-problem-like-maria/a-problem-like-destructuring-declarations-95f10375ea8a | |
data class Song( | |
val artist: String, | |
// val album: String, // once this line gets uncommented | |
val name: String | |
) | |
// this line of code will still compile, but instead of "name" it contains the field of album, no compiler warning ! | |
val (artist, name) = song | |
// Because compiled code of a destructuring declaration will call the componentN functions on the class | |
val artist = song.component1() | |
val name = song.component2() // clash with "album" ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment