kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Introspecting local functions, lambdas, anonymous functions and local variables is not yet fully supported in Kotlin reflection
此异常来自数据类的toString()
。
数据类包含一个 lambda。
我无法在我的环境中重现它。
我需要重写 toString() 来排除 lambda 吗?或者数据类中根本不允许使用 lambda?
data class PersistJob(
private val id: Int,
private val delay: Long = 10_000L,
private val maxDelay: Long = 60_000L,
private val iteration: Int = 0,
private val block: suspend (Int) -> Boolean) {
fun getDelay() = minOf(delay, maxDelay)
fun withDelayIncreased() = copy(
delay = minOf(delay * 2, maxDelay),
iteration = iteration + 1)
suspend fun execute() = block(iteration)
}
产生错误的行:
val job: PersistJob = ...
log.debug("start job id($id): $job")`// job.toString()
堆栈跟踪:
at kotlin.reflect.jvm.internal.EmptyContainerForLocal.fail(SourceFile:41)
at kotlin.reflect.jvm.internal.EmptyContainerForLocal.getFunctions(SourceFile:37)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.findFunctionDescriptor(SourceFile:145)
at kotlin.reflect.jvm.internal.KFunctionImpl$descriptor$2.invoke(SourceFile:54)
at kotlin.reflect.jvm.internal.KFunctionImpl$descriptor$2.invoke(SourceFile:34)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(SourceFile:93)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(SourceFile:32)
at kotlin.reflect.jvm.internal.KFunctionImpl.getDescriptor(SourceFile)
at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.renderLambdaToString(SourceFile:59)
at kotlin.jvm.internal.Reflection.renderLambdaToString(SourceFile:80)
at kotlin.jvm.internal.Lambda.toString(SourceFile:22)
at java.lang.String.valueOf(String.java:2683)
at java.lang.StringBuilder.append(StringBuilder.java:129)
最佳答案
它看起来像是 Kotlin lambda 中的一个错误。
此代码足以重现异常:
({i: Int -> true}).toString()
我建议您在 youtrack.jetbrains.com/issues/KT 上发布问题,看看团队对此有何评论。
关于exception - Kotlin/Android – 带有 lambda 的数据类中的 KotlinReflectionInternalError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48021156/