Skip to content

Instantly share code, notes, and snippets.

@dvbobrov
Last active September 8, 2015 23:03
Show Gist options
  • Save dvbobrov/97bea562f23f16a238d3 to your computer and use it in GitHub Desktop.
Save dvbobrov/97bea562f23f16a238d3 to your computer and use it in GitHub Desktop.
Magic
localhost:main dmitry$ javap -p -c X\$Y
Compiled from "X.scala"
public class X$Y {
public X$Y();
Code:
0: aload_0
1: invokespecial #9 // Method java/lang/Object."<init>":()V
4: return
}
localhost:main dmitry$ javap -p -c X\$Y\$
Compiled from "X.scala"
public class X$Y$ {
public static final X$Y$ MODULE$;
private final long y;
public static {};
Code:
0: new #2 // class X$Y$
3: invokespecial #12 // Method "<init>":()V
6: return
public long y();
Code:
0: aload_0
1: getfield #17 // Field y:J
4: lreturn
public X$Y$();
Code:
0: aload_0
1: invokespecial #19 // Method java/lang/Object."<init>":()V
4: aload_0
5: putstatic #21 // Field MODULE$:LX$Y$;
8: aload_0
9: invokestatic #26 // Method java/lang/System.nanoTime:()J
12: putfield #17 // Field y:J
15: return
}
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException, InterruptedException, NoSuchFieldException {
Class<?> cls = X$Y$.class;
Constructor<?> constructor = cls.getConstructor();
Field module = cls.getField("MODULE$");
Method y = cls.getMethod("y");
System.out.println(y.invoke(module.get(null)));
Object o = constructor.newInstance();
System.out.println(y.invoke(module.get(null)));
Thread.sleep(10);
Object o1 = constructor.newInstance();
System.out.println(y.invoke(module.get(null)));
System.out.println(y.invoke(o));
System.out.println(y.invoke(o1));
}
class X {
}
object X {
val x = "test"
class Y {
}
object Y {
val y = System.nanoTime()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment