Well, one thing which is unfortunate is the cost o...
# announcements
s
Well, one thing which is unfortunate is the cost of the companion object. Especially when it comes to Android where in many cases the only thing you want to put there is the TAG string. And yet one more class and one more instances is going to get created just for the sake of one constant.
s
If you use TAG only for logging, take a look at Timber https://github.com/JakeWharton/timber
k
That is actually my problem with it
s
Sure, Timber might workaround problem with TAG constant on Android, but there is many other cases when you need one static constant and yet you have to pay the cost of the companion object.
Pretty much the whole point of the comment is companion object adds overhead which is not worth its benefits IMHO. In fact I have to yet see a good usecase for companion object ….
👍 1
l
Proguard should remove the companion objects when they're not used
g
Just use top level
const
instead for TAG or any other constant. You can even make it private