Search code examples
kotlinclass

How to get name of any class?


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())
}

Solution

  • val c = String::class
    println(c.simpleName)
    
    $ String