글

라벨이 sealed class인 게시물 표시

코틀린 (Kotlin) 내부 클래스 sealed class 정리

내부 클래스 자바에서 내부 클래스는 바깥쪽 클래스에 대해 참조 를 합니다. 그래서 static class 로 선언하여 바깥쪽 클래스에 대한 참조를 제거할 수 있습니다. 코틀린에서는 기본적으로 static 중첩 클래스 와 같습니다. 그리고 바깥쪽 클래스에 대한 참조를 갖고 싶으면 inner 변경자 를 붙입니다. class Button : View {     override fun getCurrentState(): State {         return ButtonState()     }     //내부 클래스     class ButtonState: State {         fun save() {             getCurrentState() //error! 바깥쪽 참조를 할 수 없다         }     }    //inner class 로 바깥쪽 클래스 참조 가능     inner class ButtonStateInner:State {         fun save() {             getCurrentState() //바깥쪽 클래스 참조 가능         }         fun getOuterReference() {             //this@클래스 로 접근 또는 생략가능         ...