Kotlin reflection unavailable

I tried to learn higher order functions from the first example of this video . Here is my code and output.

the code

fun lowercase(value: String) = value.toLowerCase()

fun higherOrder(value:String, op: (String) -> String) : String {
    println("Executing higher order fun $op")
    return op(value)
}

fun main(args: Array<String>) {
    println(higherOrder("HELLO", ::lowercase))
    println(higherOrder("hello", {it -> lowercase(it)}))
    println(higherOrder("HeLlo", { x -> lowercase(x) }))
    println(higherOrder("Hello", { lowercase(it) }))
}

Output

Executing higher order fun function lowercase (Kotlin reflection is not available)
hello
Executing higher order fun Function1<java.lang.String, java.lang.String>
hello
Executing higher order fun Function1<java.lang.String, java.lang.String>
hello
Executing higher order fun Function1<java.lang.String, java.lang.String>
hello

Process finished with exit code 0

So my question is: why print Kotlin's Reflection is not available ?

+4
source share
1 answer

Full reflection requires a library kotlin-reflectin addition to kotlin-stdlib. If full reflection is available, it will probably have a more complete toString(), therefore message.

+7
source

Source: https://habr.com/ru/post/1678478/


All Articles