You can never be sure if something stay forever because nobody knows
what future will bring us. Neverthelless I don't think there will be
occur so many cases which require a change of the current behavior. In
Scala currently it is impossible to directly generate private variables
without creating a Getter - the compiler enforces an access of the
Getter. Thus, there is no need to change the name of the variable
because no one is able to touch it.
Another point to mention is backwards compatibility. No one will change
existing behavior when it breaks huge code bases.
But who knows if one day we get a language feature which requires
direct access to the private variable of Scalas vals and vars...
On Tue 28 Aug 2012 11:13:17 PM CEST, Ant Kutschera wrote:
> Hi,
>
> I have the following Scala class:
>
> class SomeClass(var someInt: Int){}
>
> The bytecode which is generated does me a favour because someInt is
> maintained as the field name.
>
> Using javap, I can see that the method call someInt() is:
>
> public int someInt();
> ...
> Code:
> ...
> 1:getfield#13; //Field someInt:I
>
> From the constants table, #13 is:
>
> const #13 = Field#2.#12;// SomeClass.someInt:I
>
> #2.#12 is:
>
> const #2 = class#1;// SomeClass
> const #12 = NameAndType#9:#10;// someInt:I