[Kotlin] Object 키워드

유존돌돌이·2023년 3월 21일
0

Kotlin

목록 보기
4/10
post-thumbnail

Java static 변수와 함수

Kotlin에서는 companion object 사용

class Person private constructor(
    val name: String,
    val age: Int
) {
    companion object {
        private const val MIN_AGE = 1
        fun newBaby(name: String) : Person {
            return Person(name, MIN_AGE)
        }
    }
}

Singleton

object singleton

익명 클래스

moveSomething(object : Movable {
	override fun move() {
    	~~~
    }
    override fun fly() {
    	~~~
    }
})

0개의 댓글