karelpeeters
10/31/2017, 10:06 PM//java code
public abstract class Test {
public abstract void run()
}
//kotlin code
fun testFoo(test: Test) = test.run()
fun main(args: Array<String>) {
testFoo(object : Test() {
override fun run() {
println("hey")
}
})
}
It just feels unnecessary, are there plans to do something about this?emmax
10/31/2017, 10:27 PMtestFoo
takes a function to begin with instead of the abstract Test class
I don't see this being supported.
https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions
Note towards the bottom
Also note that this feature works only for Java interop; since Kotlin has proper function types, automatic conversion of functions into implementations of Kotlin interfaces is unnecessary and therefore unsupported.
karelpeeters
10/31/2017, 10:28 PMemmax
10/31/2017, 10:31 PMkarelpeeters
10/31/2017, 10:31 PMemmax
10/31/2017, 10:32 PMkarelpeeters
10/31/2017, 10:33 PMpublic void
feels so ugly now.bj0
10/31/2017, 10:50 PMtestFoo
and create the object in there:inline fun runnable(crossinline init: Runnable.() -> Unit) = object : Runnable {
override fun run() = this.init()
}