반응형
class Person private constructor(){
companion object {
fun create(): Person{
countCreated++
return Person()
}
var countCreated = 0
private set
}
}
fun main(args: Array<Any>){
val a = Person.create()
val b = Person.create()
println(Person.countCreated)
}
반응형
'Android > Kotlin' 카테고리의 다른 글
고차 함수(Higher-order Function) (0) | 2018.12.09 |
---|---|
람다식(Lambda Expression) & 익명함수(Anonymous Function) (0) | 2018.12.09 |
캐스팅(Casting) (0) | 2018.12.09 |
ExoPlayer (0) | 2018.11.28 |
Intent (0) | 2018.11.28 |