Kotlin - 내부 클래스(Inner Class)의 구성 형식

CODEDRAGON Development/Kotlin

반응형



 

 

Kotlin - 내부 클래스(Inner Class) 구성 형식

내부 클래스는 class앞에 inner 키워드로 정의할 있습니다.

 

class OuterClass {

//…

inner class InnerClass {

 

}

//

 

}

 

val outer = OuterClass()

val inner = outer.InnerClass()

var inner = OuterClass().InnerClass()

 

 

 

inner 클래스는 멤버이므로 외부클래스의 객체 생성없이 직접 객체 생성할 수 없습니다.

var inner = OuterClass.InnerClass()

ERROR: Constructor of inner class InnerClass can be called only with receiver of containing class

 

 

https://kotlinlang.org/docs/reference/nested-classes.html


 

 


반응형

'Development > Kotlin' 카테고리의 다른 글

Kotlin - Loop control  (0) 2019.02.07
Kotlin - 프로퍼티(Property)  (0) 2019.02.01
Kotlin - 배열(Array)  (0) 2019.01.20
STEP1 - 접근 가능 영역범위 (Kotlin)  (0) 2019.01.14
Kotlin - 배열 요소로 접근하여 사용  (0) 2019.01.03