gh-pages / com.nextfaze.devfun.inject / CapturingInstanceProvider / <init>

<init>

CapturingInstanceProvider(instanceClass: KClass<T>, instance: () -> T?)

An instance provider that requests an instance of a class from a captured lambda.

Be aware of leaks! The lambda could implicitly hold a local this reference.

Be wary of using a typealias as a type - the resultant function “type” itself is used at compile time. e.g.

typealias MyStringAlias = () -> String?
val provider1 = captureInstance<MyStringAlias> { ... }

typealias MyOtherAlias = () -> Type?
// will be triggered for MyStringAlias and MyOtherAlias since behind the scenes they are both kotlin.Function0<T>
val provider2 = captureInstance<MyOtherAlias> { ... }

See Also

captureInstance