Skip to content

Instantly share code, notes, and snippets.

@jackywyz
Forked from codahale/Regular.java
Created September 22, 2011 09:37
Show Gist options
  • Save jackywyz/1234421 to your computer and use it in GitHub Desktop.
Save jackywyz/1234421 to your computer and use it in GitHub Desktop.
An example of the utility of private[this]
class Regular {
private var i = 0
def inc() {
i += 1
}
def get = i
}
class Special {
private[this] var i = 0
def inc() {
i += 1
}
def get = i
}
//decompiled with JD-GUI
import scala.ScalaObject;
import scala.reflect.ScalaSignature;
@ScalaSignature(bytes="\006\00192A!\001\002\001\013\t9!+Z4vY\006\024(\"A\002\002\017q*W\016\035;z}\r\0011c\001\001\007\035A\021q\001D\007\002\021)\021\021BC\001\005Y\006twMC\001\f\003\021Q\027M^1\n\0055A!AB(cU\026\034G\017\005\002\020%5\t\001CC\001\022\003\025\0318-\0317b\023\t\031\002CA\006TG\006d\027m\0242kK\016$\b\"B\013\001\t\0031\022A\002\037j]&$h\bF\001\030!\tA\002!D\001\003\021\035Q\002\0011A\005\nm\t\021![\013\0029A\021q\"H\005\003=A\0211!\0238u\021\035\001\003\0011A\005\n\005\nQ![0%KF$\"AI\023\021\005=\031\023B\001\023\021\005\021)f.\033;\t\017\031z\022\021!a\0019\005\031\001\020J\031\t\r!\002\001\025)\003\035\003\tI\007\005C\003+\001\021\0051&A\002j]\016$\022A\t\005\006[\001!\taG\001\004O\026$\b")
public class Regular
implements ScalaObject
{
private int i = 0;
private int i() { return this.i; }
private void i_$eq(int paramInt) { this.i = paramInt; }
public void inc() {
i_$eq(i() + 1);
}
public int get() {
return i();
}
}
Compiled from "example.scala"
public class Regular extends java.lang.Object implements scala.ScalaObject{
public void inc();
Code:
0: aload_0
1: aload_0
2: invokespecial #17; //Method i:()I
5: iconst_1
6: iadd
7: invokespecial #19; //Method i_$eq:(I)V
10: return
public int get();
Code:
0: aload_0
1: invokespecial #17; //Method i:()I
4: ireturn
public Regular();
Code:
0: aload_0
1: invokespecial #25; //Method java/lang/Object."<init>":()V
4: aload_0
5: iconst_0
6: putfield #11; //Field i:I
9: return
}
// decompiled with JD-GUI
import scala.ScalaObject;
import scala.reflect.ScalaSignature;
@ScalaSignature(bytes="\006\001\0352A!\001\002\001\013\t91\013]3dS\006d'\"A\002\002\017q*W\016\035;z}\r\0011c\001\001\007\035A\021q\001D\007\002\021)\021\021BC\001\005Y\006twMC\001\f\003\021Q\027M^1\n\0055A!AB(cU\026\034G\017\005\002\020%5\t\001CC\001\022\003\025\0318-\0317b\023\t\031\002CA\006TG\006d\027m\0242kK\016$\b\"B\013\001\t\0031\022A\002\037j]&$h\bF\001\030!\tA\002!D\001\003\021\031Q\002\001)Q\0057\005\t\021\016\005\002\0209%\021Q\004\005\002\004\023:$\b\"B\020\001\t\003\001\023aA5oGR\t\021\005\005\002\020E%\0211\005\005\002\005+:LG\017C\003&\001\021\005a%A\002hKR,\022a\007")
public class Special
implements ScalaObject
{
private int i = 0;
public void inc() {
this.i += 1;
}
public int get() {
return this.i;
}
}
Compiled from "example.scala"
public class Special extends java.lang.Object implements scala.ScalaObject{
public void inc();
Code:
0: aload_0
1: aload_0
2: getfield #12; //Field i:I
5: iconst_1
6: iadd
7: putfield #12; //Field i:I
10: return
public int get();
Code:
0: aload_0
1: getfield #12; //Field i:I
4: ireturn
public Special();
Code:
0: aload_0
1: invokespecial #19; //Method java/lang/Object."<init>":()V
4: aload_0
5: iconst_0
6: putfield #12; //Field i:I
9: return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment