there is no way to access a field of a class direc...
# getting-started
f
there is no way to access a field of a class directly from the outside ever?
k
I think you can only access the backing field from the setter/getter and using reflection.
f
you mean the backing field through the getter and setter?
not directly?
I have to look into reflection tho
k
You can access the backing field with the
field
soft keyword:
Copy code
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
but the field keyword only works inside the class, right?
I meant "outside of the class"
k
Yes.
s
If you annotate a property with
@JvmField
, it'll be compiled into a normal field
f
ok thank you