Kotlin reflection is not available

Viewed 12433

I was trying to learn higher order functions from the first example of this video. Here's my code and output.

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 does it print Kotlin reflection is not available?

2 Answers

add kotlin-reflect library

 implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0'

I try it, it works.

Related