Created
January 14, 2016 10:44
-
-
Save passy/97f77a7c1da8a68180f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
public static void main(String... args) { | |
new Inner(); | |
} | |
// Private class, package-level constructor. | |
private static class Inner { | |
Inner() { | |
System.out.println("Hello, world."); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiled from "TestClass.java" | |
class TestClass$Inner { | |
TestClass$Inner(); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; | |
7: ldc #3 // String Hello, world. | |
9: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V | |
12: return | |
} | |
Compiled from "TestClass.java" | |
public class TestClass { | |
public TestClass(); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: return | |
public static void main(java.lang.String...); | |
Code: | |
0: new #2 // class TestClass$Inner | |
3: dup | |
4: invokespecial #3 // Method TestClass$Inner."<init>":()V | |
7: pop | |
8: return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
public static void main(String... args) { | |
new Inner(); | |
} | |
static class Inner { | |
private Inner() { | |
System.out.println("Hello, world."); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiled from "TestClass.java" | |
class TestClass$1 { | |
} | |
Compiled from "TestClass.java" | |
class TestClass$Inner { | |
private TestClass$Inner(); | |
Code: | |
0: aload_0 | |
1: invokespecial #2 // Method java/lang/Object."<init>":()V | |
4: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream; | |
7: ldc #4 // String Hello, world. | |
9: invokevirtual #5 // Method java/io/PrintStream.println:(Ljava/lang/String;)V | |
12: return | |
TestClass$Inner(TestClass$1); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method "<init>":()V | |
4: return | |
} | |
Compiled from "TestClass.java" | |
public class TestClass { | |
public TestClass(); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: return | |
public static void main(java.lang.String...); | |
Code: | |
0: new #2 // class TestClass$Inner | |
3: dup | |
4: aconst_null | |
5: invokespecial #3 // Method TestClass$Inner."<init>":(LTestClass$1;)V | |
8: pop | |
9: return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Private inner classes don't add additional overhead in terms of methods or class files, whereas private constructors infamously do.