Skip to content

Instantly share code, notes, and snippets.

@alblue
Created October 4, 2015 13:36
Show Gist options
  • Save alblue/6cc55e4a27241dc65a82 to your computer and use it in GitHub Desktop.
Save alblue/6cc55e4a27241dc65a82 to your computer and use it in GitHub Desktop.
Simple testcase to determine if inner classes or lambdas take up more space
package foo;
public class X {
public static final Runnable y = new Y();
public static final Runnable z = new Z();
static class Y implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Hello world");
}
}
static class Z implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Hello again");
}
}
}
package foo;
public class Z {
public static final Runnable y = () -> System.out.println("Hello world");
public static final Runnable z = () -> System.out.println("Hello again");
}
@alblue
Copy link
Author

alblue commented Oct 4, 2015

File sizes for the above:

Inner classes:

  • 459 X$Y.class
  • 459 X$Z.class
  • 404 X.class

Lambdas:

  • 1130 Z.class

Compiled with 1.8.0_60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment