I am trying to create function references in Kotlin, my understanding is I should be able to access the generated KFunctionN interfaces at compile time, but I am getting an 'Unresolved reference' compilation error for KFunction1<T, R>.
For example:
inline fun <reified T : Any, reified R : Any> passFn(someFn: KFunction1<T, R>) {
//consume someFn
}
I have kotlin-reflect on the class path and working fine. Any ideas what I am missing?
I am using Kotlin 1.3.21 and IntelliJ 2018.3.
This looks like an IDE issue, I have typed the import the import kotlin.reflect.KFunction1 and compiler error goes away.
However, if you add an expression/statement which returns a KFunction1 type and explicitly declare the type, the Intellij imports it correctly. For example;
"\\s+".toRegex()::matches
Can be extracted as
val kFunction1: KFunction1<@ParameterName(name = "input") CharSequence, Boolean> = "\\s+".toRegex()::matches
Ok, very simple fix for this - you need to manually add the KFunctionN import, IntelliJ won't resolve it automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With