Outer inner nested local


Source code

1class OuterInnerNestedLocal {
2
3 Integer fieldOuter = new Integer(10000);
4
5 class Inner {
6 void methodInner() {
7 fieldOuter.hashCode();
8 }
9 }
10
11 static class Nested {
12 void methodNested() {
13 }
14 }
15
16 void methodOuter() {
17 Integer fieldLocal = new Integer(80000);
18 final int fieldLocalFinal = 90000;
19
20 class Local {
21 void methodLocal() {
22 }
23 }
24
25 class LocalWithAccesToOuter {
26 void methodLocalWithAccesToOuter() {
27 fieldLocal.hashCode();
28 new Integer(fieldLocalFinal);
29 }
30 }
31
32 new Inner().methodInner();
33 new Nested().methodNested();
34 new Local().methodLocal();
35 new LocalWithAccesToOuter().methodLocalWithAccesToOuter();
36 }
37
38}
39

Bytecode






Comment

Inner and local classes are similar to each other, with the exception of EnclosingMethod attribute in local class. Both classes have single constructor with one parameter - reference to outer class. Reference is saved as synthetic instance variable this$0 and may be used further for access to outer class. Reference to outer class is passed as constructor parameter and saved even if inner/local don't use it (according to source code).

Java compiler version: 21
Other examples
Main page