vendredi 29 décembre 2017

Kotlin/Android – KotlinReflectionInternalError in Data Class with a lambda

kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Introspecting local functions, lambdas, anonymous functions and local variables is not yet fully supported in Kotlin reflection

This exception comes from toString() of a data class.

The data class contains a lambda.

I can't reproduce it in my environment.

Do I need to override toString() to exclude the lambda? Or lambdas are not allowed in data classes at all?

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)
}

Line producing the error:

val job: PersistJob = ...
log.debug("start job id($id): $job")`// job.toString()





Aucun commentaire:

Enregistrer un commentaire