-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOuterMain.java
More file actions
37 lines (32 loc) · 1.38 KB
/
Copy pathOuterMain.java
File metadata and controls
37 lines (32 loc) · 1.38 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
package lambda.lambda6;
public class OuterMain {
private String message = "외부 클래스";
public void execute() {
Runnable anonymouse = new Runnable() {
private String message = "익명 클래스";
@Override
public void run() {
// 익명 클래스에서의 this는 익명 클래스의 인스턴스를 가리킴
System.out.println("[익명 클래스] this: " + this);
System.out.println("[익명 클래스] this.class: " + this.getClass());
System.out.println("[익명 클래스] this.message: " + this.message);
}
};
// 2. 람다 예시
Runnable lambda = () -> {
// 람다에서의 this는 람다가 선언된 클래스의 인스턴스(즉, 외부 클래스) 가리킴
System.out. println("[람다] this: " + this);
System.out.println("[람다] this.class: " + this.getClass());
System.out.println("[람다] this.message: " + this.message);
};
anonymouse.run();
System.out.println("-------------------------");
lambda.run();
}
public static void main(String[] args) {
OuterMain outer = new OuterMain();
System.out.println("[외부 클래스] " + outer);
System.out.println("-------------------------");
outer.execute();
}
}