Kotlin에 최근 추가된 Context parameters를 살펴보고 있어요.
어떤 상황에서는 코드 블록에 컨텍스트가 하나 이상 있어도 직접 참조할 방법이 없을 수 있더군요(변수에 연결되어 있지 않아요). 컨텍스트 매개변수를 받는 함수를 호출할 때 전달하는 용도로만 쓸 수 있어요.
이런 이름 없는 컨텍스트를 얻는 관례적인 방법이 있나요?
접근하려고 작은 도우미를 만들었어요:
context(current: C) inline fun <reified C> grabContext() = current
그런데 이미 표준 함수가 있을지도 모르겠네요.
영어에서 번역·원문 보기I'm exploring Kotlin's recent addition, Context parameters.
Under certain circumstances, a code block can have one or several contexts available without a direct way to reference them (there's no variable bound to them). They're accessible solely to forward into calls of functions taking context parameters.
What's the conventional way to retrieve one of these unnamed contexts?
I made this tiny utility to get at it:
context(current: C) inline fun <reified C> grabContext() = current
However, perhaps a standard function already does this.