I am trying to make an extension function for logging. I want to send Any
as a parameter and get its name. But can not find how to get name of Any
class. Have any idea about it?
fun MainActivity.log(claz: Objects,any: Any){
Log.d("Main", claz.name + any.toString())
}
val c = String::class
println(c.simpleName)
$ String
Use yourClassInstance::class.simpleName
:
fun MainActivity.log(claz: Objects, any: Any){
Log.d("Main", "${claz::class.simpleName} ${any::class.simpleName}")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With