Foggy day

Kotlin - data class destructuring 본문

Kotlin

Kotlin - data class destructuring

jinhan38 2021. 4. 8. 23:55
class KotlinPlayGroundActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kotlin_play_ground)

        val human = Human("Man", 30, "jerome")
        val (sex, age, name) = human
        println("sex : $sex, age : $age, name : $name")
	///// sex : Man, age : 30, name : jerome //////
    }
}

data class Human(
    val sex: String,
    val age: Int,
    val name: String,
)

'Kotlin' 카테고리의 다른 글

Kotlin - Coroutine cancel  (0) 2021.04.10
Kotlin - coroutine Scope basic  (0) 2021.04.10
Kotlin - Object Expressions  (0) 2021.04.08
Kotlin - when, for  (0) 2021.04.06
Kotlin - recursive function -2 : TCE  (0) 2021.03.21