Files
kotlin/compiler/testData/codegen/boxWithStdlib/reflection/mapping/platformStatic/objectFunction.kt
Alexander Udalov ced1edcf98 Prohibit callable references to object members
To be able to make them more useful in the future, i.e. bound to the object
instance
2015-10-14 20:45:56 +03:00

21 lines
563 B
Kotlin
Vendored

import kotlin.jvm.JvmStatic as static
import kotlin.reflect.KFunction
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
object O {
@static fun foo(s: String): Int = s.length()
}
fun box(): String {
val foo = O::class.members.single { it.name == "foo" } as KFunction<*>
val j = foo.javaMethod ?: return "Fail: no Java method found for O::foo"
assertEquals(3, j.invoke(null, "abc"))
val k = j.kotlinFunction ?: return "Fail: no Kotlin function found for Java method O::foo"
assertEquals(3, k.call(O, "def"))
return "OK"
}