Hello I have an interface like the following. For ...
# announcements
j
Hello I have an interface like the following. For some reason, if I try to pass a method reference like
MyJavaClass::hasData
as an
IsStateRunningCheck
argument I get the following error. Found KFunction1 and not my interface. Is this an instance of SAM conversion not working properly or is there something I can do to make this possible.
Copy code
@FunctionalInterface
protected interface IsStateRunningCheck<T> {
    boolean isStateRunning(T state);
}
For instance:
Copy code
fun myFooMethod(stateCheck: IsStateRunnningCheck<Int>) { ... }

fun test() {
   myFooMethod(MyJavaClass::hasData) // fails to compile
   myFooMyethod( { it.hasData() }) // works fine
}

// I don't think it matters if this is java or not
class MyJavaClass<Int> { 
  boolean hasData(int x) { return true; }
}
e
SAM is 1.4 or later IIRC
j
Gotcha thank you. I thought it had something but maybe not.
Actually, looking at it again, we have a Java interface and from what I understand Kotlin 1.4 is only adding SAM conversion for Kotlin interfaces. How I read it is 1.3 should already support Java SAM conversion