Foggy day
Kotlin - variable initialization 본문
It is about initialization of lazy.
class KotlinPlayGroundActivity : AppCompatActivity() {
val name: String by lazy { getName() }
val name2: String by lazy(::getName)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin_play_ground)
println("hello")
println("name 1 : $name")
println("name 2 : $name2")
}
@JvmName("getName1")
private fun getName(): String {
println("Calling name...")
return "Name is Jinhan"
}
}
'Kotlin' 카테고리의 다른 글
Kotlin - companion object (0) | 2021.03.16 |
---|---|
Kotlin - destructing (0) | 2021.03.16 |
Kotlin - data class (0) | 2021.03.15 |
Kotlin - class extension (0) | 2021.03.15 |
Kotlin - constructor (0) | 2021.03.15 |