package reified
import java.util.*
import kotlin.reflect.KClass
val valuesInjectFnc = HashMap<KClass<out Any>, Any>()inline fun <reified T : Any> registerFnc(noinline value: Function0<T>) {
valuesInjectFnc[T::class] = value
}inline fun <reified T : Any> injectFnc(): Lazy<Function0<T>> = lazy(LazyThreadSafetyMode.NONE) {
(valuesInjectFnc[T::class] ?: throw Exception(“no inject ${T::class.simpleName}”)) as Function0<T>
}
class Box
class Boxer{
val box:()->Box by injectFnc()
}
fun main(args: Array<String>) {
val box = Box()
registerFnc({box})
println(Boxer().box())
}
Actual:
Exception in thread “main” java.lang.NoSuchMethodError: kotlin.jvm.internal.Intrinsics.reifyClassLiteral(Ljava/lang/String;)V
at reified.MainKt$injectFnc$1.invoke(Main.kt:13)
at reified.MainKt$injectFnc$1.invoke(Main.kt)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:148)
at kotlin.LazyKt.get(Lazy.kt:77)
at reified.Boxer.getBox(Main.kt)
at reified.MainKt.main(Main.kt:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Expected: No err.
What is mean this err? How to avoid?