Foggy day

Kotlin - data class 본문

Kotlin

Kotlin - data class

jinhan38 2021. 3. 15. 21:27

 

If you declare a value of variable in constructor, you don't need add parameter when you create class.

class KotlinPlayGroundActivity : AppCompatActivity() {

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

        val person = Person("jinhan")
        println("person name : ${person.name}, registered : ${person.registered}")

    }

    data class Person(val name: String, val registered: Instant = Instant.now())
}

 

'Kotlin' 카테고리의 다른 글

Kotlin - companion object  (0) 2021.03.16
Kotlin - destructing  (0) 2021.03.16
Kotlin - class extension  (0) 2021.03.15
Kotlin - constructor  (0) 2021.03.15
Kotlin - variable initialization  (0) 2021.03.15