https://kotlinlang.org logo
Title
f

Florian

10/26/2019, 1:35 PM
there is no way to access a field of a class directly from the outside ever?
k

karelpeeters

10/26/2019, 1:38 PM
I think you can only access the backing field from the setter/getter and using reflection.
f

Florian

10/26/2019, 2:18 PM
you mean the backing field through the getter and setter?
not directly?
I have to look into reflection tho
k

karelpeeters

10/26/2019, 2:20 PM
You can access the backing field with the
field
soft keyword:
var x: Int = 0
    get() { return field }
    set(value) { field = value }
And the answer to any question "can you access X?" is always going to be "yes, with reflection"
f

Florian

10/26/2019, 2:51 PM
but the field keyword only works inside the class, right?
I meant "outside of the class"
k

karelpeeters

10/26/2019, 3:18 PM
Yes.
s

serebit

10/26/2019, 8:20 PM
If you annotate a property with
@JvmField
, it'll be compiled into a normal field
f

Florian

10/28/2019, 8:25 AM
ok thank you