if I write a class like `class Foo { private val b...
# compiler
p
if I write a class like
class Foo { private val bar = "bar" }
, is compiler smart enough to convert bar to static field (companion object)?
f
Have you checked the generated bytecode? IntelliJ has under tools a Kotlin entry where you can get the bytecode, from there you can let it generate the Java code. This will give you the answer. Afaik it is going to create a normal field.
1
d
Such optimization will break contracts about compiled code, which may affect, for example, reflection, so it can not be performed
👍 2