-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodeRefEx1.java
More file actions
32 lines (22 loc) · 1.15 KB
/
Copy pathMethodeRefEx1.java
File metadata and controls
32 lines (22 loc) · 1.15 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
package methodref;
import java.util.function.Supplier;
public class MethodeRefEx1 {
public static void main(String[] args) {
// 1. 정적 메서드 참조
Supplier<String> staticMethod1 = () -> Person.greeting();
Supplier<String> staticMethod2 = Person::greeting; // 클래스::정적 메서드
System.out.println("staticMethod1 = " + staticMethod1.get());
System.out.println("staticMethod2 = " + staticMethod2.get());
// 2. 특정 객체의 인스턴스 참조
Person person = new Person("Choi");
Supplier<String> instanceMethod1 = () -> person.introduce();
Supplier<String> instanceMethod2 = person::introduce; // 객체::인스턴스메서드
System.out.println("instanceMethod1 = " + instanceMethod1.get());
System.out.println("instanceMethod2 = " + instanceMethod2.get());
// 3. 생성자 참조
Supplier<Person> newPerson1 = () -> new Person();
Supplier<Person> newPerson2 = Person::new; // 클래스::new
System.out.println("newPerson1 = " + newPerson1.get());
System.out.println("newPerson2 = " + newPerson2.get());
}
}