Lambdas and java interop


#1

It appears Kotlin does not let Java call Kotlin higher order functions. Is that right? E.g.,

fun hello( thing: ()->String ) { ... }

I can’t call this from Java. I’ve tried with a Java lambda. I’ve also check out the bytecode Kotlin generates for the lambda argument type and it doesn’t appear to be a functional interface. Or am I missing something. Thanks!


#2

You can in fact call this function from Java, and the Kotlin interfaces used to represent function types are in fact functional interfaces. What code did you write for the call, and which problems did you see?


#3

JAVA:

TestMe testMe = new TestMe();

// ERROR: Error:(5, 8) java: cannot access kotlin.jvm.functions.Function0 class file for kotlin.jvm.functions.Function0 not found
testMe.hello( () -> "hi" ); 

KOTLIN:

class TestMe {
    fun hello( thing: ()->String ) {
    }
}

#4

Oh geez, nm… looking at that message now (file not found) i probably don’t have the kotlin jdk specified in my module