I’m running into a weird situation where the properties of my companion object are static rather than being part of the companion itself. They do not have a
@JvmStatic
annotation. Anyone have any idea what’s going on? All of the documentation I can find seems to indicate that only the companion object itself should have static. This is causing problems the framework I’m using is trying to use reflection against the local properties and because they are static it’s not working. (This is on 1.3.0 in case it matters)
d
diesieben07
11/14/2018, 6:54 PM
const val
properties become
static
, too.
d
dalexander
11/14/2018, 6:55 PM
That’s good to know, but I’m using `var`s in this case.
dalexander
11/14/2018, 6:56 PM
Copy code
class Foo {
companion object {
var temp = 3
var bar = "asdf"
init {
val fields = Foo.Companion.javaClass.fields
fields.forEach {
println(it.name)
}
}
}
}
This is the test code I’m using to try and isolate the issue.
d
diesieben07
11/14/2018, 6:59 PM
Huh, curious, I did not know that. It seems that the fields are placed in the class always, only getter and setter go into the companion.