Reputation: 5414
I'm trying to statically get an object's name (For logging uses)
The equivalence for:
public class SomeClass
{
private static final String TAG = SomeClass.class.getSimpleName()
}
In Kotlin:
object SomeObject
{
private const val TAG = ?
}
Upvotes: 3
Views: 504
Reputation: 17829
If you are using it in Android application, i would suggest you to do it like following: (packageName:className)
object SomeObject
{
private val TAG = "${SomeObject::class.java.`package`.name}:${SomeObject::class.simpleName}"
}
Doing so you can ensure that tag name for any other class wont be duplicate. It is really helpful, if you are creating a lib/code snippet that someone can use. Otherwise having same tag name may lead to runtime errors.
Upvotes: 0