Kotlin : Koans 예제 invoke operator 의 리턴타입에 관한 궁금증.
조회수 613회
class Invokable {
var numberOfInvocations: Int = 0
private set
operator fun invoke(): Invokable {
numberOfInvocations++
return this
}
}
fun invokeTwice(invokable: Invokable) = invokable()()
Kotlin 의 Koans 예제를 풀어보고 있습니다. invoke operator 를 구현하는 문제이고, 위 코드는 정답 내용입니다. ( https://play.kotlinlang.org/koans/Conventions/Invoke/Task.kt )
invoke operator 의 반환형이 왜 Invokable 로 정의된 것일까요?
댓글 입력