Access a field without calling a setter


I have a proposal, since i could not find how to do this.

In Java, we can call a field to set value directly to it like so: this.field = x inside the defining class.
In Kotlin when we try to do this, it calls the set(value) method from that field.

I saw that there is @JVMField annotation which doesn’t generate getters and setters automatically, and my proposal goes like this:
It would be useful to have like a @Field annotation that when called alongside “this.field” could call the field itself and not the set method.
Is something like this possible and worth doing?


Not worth doing in my opinion. What are your goals?


To have a custom set method for the outside and to internally set the field when some other function is called.


Use backing properties like the documentation says. It hurts, but it is supposed to hurt because you should try to avoid this if possible.