All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.fr.xgouchet.elmyr.inject.reflect.SetterExt.kt Maven / Gradle / Ivy

The newest version!
package fr.xgouchet.elmyr.inject.reflect

import kotlin.reflect.KMutableProperty
import kotlin.reflect.jvm.isAccessible

@Suppress("TooGenericExceptionCaught", "SwallowedException")
internal fun KMutableProperty.Setter<*>.invokePrivate(target: Any?, vararg params: Any?) {
    val wasAccessible = this.isAccessible

    // make field accessible
    isAccessible = true

    // Set the field value
    @Suppress("SpreadOperator")
    this.call(target, *params)

    // reset accessibility
    isAccessible = wasAccessible
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy