- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
will implicit getters/setters stay?
Wed, 2008-12-17, 19:06
Hello,
I was curious about Java bytecode generated for private fields and inner classes and discovered that for every val/var (even private) Scala compiler is generating a public getter and setter (for vars).
Are there any plans for removing this? Was this implemented intentionally or is it just a side effect of other decisions?
No. I'm not concerned about isolation or executions speed. :-)
Actually I want to abuse it to experiment with instrumenting classes, detecting field read/write... (OnFieldModified event?) through runtime bytecode manipulation.
// javap output for class A with field a
public final void A$$a_$eq(int);
Signature: (I)V
Code:
0: aload_0
1: iload_1
2: putfield #13; //Field A$$a:I
5: return
public final int A$$a();
Signature: ()I
Code:
0: aload_0
1: getfield #13; //Field A$$a:I
4: ireturn
Szymon
I was curious about Java bytecode generated for private fields and inner classes and discovered that for every val/var (even private) Scala compiler is generating a public getter and setter (for vars).
Are there any plans for removing this? Was this implemented intentionally or is it just a side effect of other decisions?
No. I'm not concerned about isolation or executions speed. :-)
Actually I want to abuse it to experiment with instrumenting classes, detecting field read/write... (OnFieldModified event?) through runtime bytecode manipulation.
// javap output for class A with field a
public final void A$$a_$eq(int);
Signature: (I)V
Code:
0: aload_0
1: iload_1
2: putfield #13; //Field A$$a:I
5: return
public final int A$$a();
Signature: ()I
Code:
0: aload_0
1: getfield #13; //Field A$$a:I
4: ireturn
Szymon
Wed, 2008-12-17, 19:47
#2
Re: Re: will implicit getters/setters stay?
Auch. There are so many meanings of "private" in programming languages... Thanks. :-)
On Wed, Dec 17, 2008 at 7:28 PM, Ismael Juma <mlists [at] juma [dot] me [dot] uk> wrote:
On Wed, Dec 17, 2008 at 7:28 PM, Ismael Juma <mlists [at] juma [dot] me [dot] uk> wrote:
Szymon Jachim <sjachim <at> gmail.com> writes:
> Hello, I was curious about Java bytecode generated for private fields and
> inner classes and discovered that for every val/var (even private) Scala
> compiler is generating a public getter and setter (for vars).
Note that it doesn't generate them if you use private[this] instead of private.
Ismael
Wed, 2008-12-17, 23:57
#3
Re: will implicit getters/setters stay?
On Wed, Dec 17, 2008 at 7:06 PM, Szymon Jachim <sjachim [at] gmail [dot] com> wrote:
> Hello,
> I was curious about Java bytecode generated for private fields and inner
> classes and discovered that for every val/var (even private) Scala compiler
> is generating a public getter and setter (for vars).
Not every private method generates a public accessor. A public
accessor (with a mangled name) is only generated when necessary, for
instance
- when it is in a trait
- or when it is accessed by some inner class
Cheers









Szymon Jachim gmail.com> writes:
> Hello, I was curious about Java bytecode generated for private fields and
> inner classes and discovered that for every val/var (even private) Scala
> compiler is generating a public getter and setter (for vars).
Note that it doesn't generate them if you use private[this] instead of private.
Ismael