-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalOuterV3.java
More file actions
47 lines (34 loc) · 1.36 KB
/
Copy pathLocalOuterV3.java
File metadata and controls
47 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package nested.local;
import java.lang.reflect.Field;
public class LocalOuterV3 {
private int outInstanceVar = 3;
public Printer process(int paramVar) {
int localVar = 1;
class LocalPrinter implements Printer {
int value = 0;
@Override
public void print() {
System.out.println("value = " + value);
//인스턴스는 지역 변수보다 더 오래 살아남는다.
System.out.println("localVar = " + localVar);
System.out.println("paramVar = " + paramVar);
System.out.println("outInstanceVar = " + outInstanceVar);
}
}
Printer printer = new LocalPrinter();
//Printer printer를 여기서 실행하지 않고 Printer 인스턴스만 반환한다.
return printer;
}
public static void main(String[] args) {
LocalOuterV3 localOuterV3 = new LocalOuterV3();
Printer printer = localOuterV3.process(2);
//printer.print()를 나중에 실행한다. process()의 슽택 프레임이 사리진 이후에 실행
printer.print();
//추가
System.out.println("필드 확인");
Field[] fields = printer.getClass().getDeclaredFields();
for (Field field : fields) {
System.out.println("field = " + field);
}
}
}