https://kotlinlang.org logo
Title
m

Marko Mitic

05/07/2019, 11:34 AM
Any plans for making any of these expressions constant?
companion object {
   const val TAG1 = this.javaClass.simpleName
   const val TAG2 = MainActivity::class.simpleName!!
}
Obfuscation mangles class names so having them assigned to constants before obfuscation pass would be greatly useful. (Or is there a way to this that I'm missing)
n

nulldev

05/07/2019, 1:07 PM
That would be confusing for use cases when you actually need the obfuscated class names
m

Marko Mitic

05/07/2019, 2:01 PM
Just skip
const
and they will be obfuscated
Properties the value of which is known at compile time can be marked as compile time constants using the
const
modifier
Obfuscation is done post-compilation, so `const val`s should have non-obfuscated names and `val`s should have obfusacted names. Am I getting this right?
k

karelpeeters

05/07/2019, 2:20 PM
That's pretty shady, I would expect the
const
qualifier to not actually change the value of things.
☝️ 1
1
m

Marko Mitic

05/07/2019, 2:28 PM
this is probably the only scenario where it actually changes behavior from regular
var
k

karelpeeters

05/07/2019, 2:28 PM
Yes, and that's the problem.
m

Marko Mitic

05/07/2019, 2:30 PM
I don't see it as a problem, obfuscation changes classes and this just "avoids" obfuscation's change
Isn't this exact scenario where
const
should be used? Other than optimizations
n

nulldev

05/07/2019, 3:17 PM
No,
const
is only used as an optimization. It should never change the variable value.
m

Marko Mitic

05/07/2019, 3:42 PM
but
const
isn't changing the value, it's the obfuscator.
const
just inlines the value as the documentation says.