What is the best way to define log TAG constant in Kotlin?

后端 未结 17 2361
暗喜
暗喜 2021-01-30 16:00

I\'m creating my first Kotlin classes in my Android application. Usually for logging purposes I have a constant with name TAG. What I would do in Java is:



        
17条回答
  •  旧时难觅i
    2021-01-30 16:23

    You can define your TAG by @JvmField as below:

    companion object {
        @JvmField val TAG: String = MyClass::class.java.simpleName
    }
    

    For more details, you can read this article : Kotlin's hidden costs

提交回复
热议问题