Kotlin
Kotlin - companion object
jinhan38
2021. 3. 16. 21:32
Kotlin don't have static. But it have companion object.
class KotlinPlayGroundActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin_play_ground)
Person.create("companion object text")
}
data class Person(val name: String, val registered: Instant = Instant.now()) {
companion object {
fun create(test: String): Person {
println("test : $test")
TODO("testing...")
}
}
}
}
If you add TODO(), it throws an exception.