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

后端 未结 17 2363
暗喜
暗喜 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条回答
  •  野性不改
    2021-01-30 16:21

    In general constants are all caps (ex. FOO) and located in the companion object:

    class MyClass {
        companion object {
            public const val FOO = 1
    
        }
    }
    

    and to define the TAG field you can use:

    private val TAG = MyClass::class.qualifiedName
    

提交回复
热议问题