Kotlin
Kotlin - destructing
jinhan38
2021. 3. 16. 21:23
If you use destructing, you can access to object properties much easier.
class KotlinPlayGroundActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin_play_ground)
val persons = listOf(Person("jinhan"), Person("jinhan2"), Person("jinhan3"))
show(persons)
}
data class Person(val name: String, val registered: Instant = Instant.now())
fun show(persons: List<Person>) {
for ((name, date) in persons) {
println("$name's registration date : $date")
}
}
}