https://kotlinlang.org logo
g

groostav

01/25/2019, 10:35 AM
Hey guys, I'm trying to convert a method reference like
SomeClass::main
into a classname for a
java -mainClass
argument. This is the best I've got
Copy code
private val KFunction<*>.instanceTypeName: String get() {
    return ((this as FunctionReference).boundReceiver::class as KClass<*>).jvmName
}
usage:
Copy code
val mainClass: String = (MyType::main).instanceTypeName
is there a better solution?
b

bdawg.io

01/25/2019, 11:03 PM
Why not just do it off of
MyType::class.jvmName
?
g

groostav

01/26/2019, 7:11 AM
just so that the
main
function has a user
u

udalov

01/30/2019, 8:00 PM
FunctionReference
is an internal API, so please don’t use it Instead, you can use
instanceParameter!!.type.jvmErasure.jvmName
2 Views