bodiam
03/06/2020, 7:05 AMinterface MyInterface<out T> {
fun process(): T
}
I need to convert this interface to Java because of SAM conversion, but I'm failing a bit here.Eivind Nilsbakken
03/06/2020, 7:30 AMinterface MyInterface<T> {
T process();
}
bodiam
03/06/2020, 7:31 AMout
parameter in my interface.bezrukov
03/06/2020, 7:31 AMfun MyInterface(lambda): MyInterface = ...
Eivind Nilsbakken
03/06/2020, 7:32 AMbodiam
03/06/2020, 7:32 AMreturn object: MyInterface<Any> {
override fun process(): String = {
// code here
}
}
bezrukov
03/06/2020, 7:35 AMinline fun <reified T> MyInterface(crossinline lambda: () -> T) = object : MyInterface<T> {
override fun process(): T {
return lambda()
}
}
then just use it
val interface: MyInterface<String> = MyInterface { "Looks like it's SAM conversion" }
val anyInterface: MyInterface<Any> = interface
return MyInterface {
// code here
}
Ruckus
03/06/2020, 2:43 PM() -> T
?bodiam
03/08/2020, 6:14 AM() -> T
?