
[TIL/Kotlin] 코틀린 고급문법_sealed 클래스, 위임된 프로퍼티, 클래스 위임
·
TIL/Kotlin
1. sealed 클래스 sealed 클래스는 자신의 중첩 클래스에만 상속을 허용하는 클래스이다. // Outer 클래스는 자신의 중첩 또는 내부 클래스에서만 상속이 가능하다. Outer 클래스 자체로는 인스턴스 생성 불가능 sealed class Outer { class One: Outer() class Two: Outer() class Three: Outer() } // Outer 클래스는 자신의 중첩 클래스에서만 상속이 가능하기 때문에 주석을 해제하면 오류 발생 // class Four: Outer() fun main() { val instance:Outer = Outer.Three() val test: Outer /* sealed 클래스는 서브클래스가 sealed 클래스 안에 모두 존재하므로, 모..