-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodReferenceExample1.java
More file actions
49 lines (32 loc) · 1.28 KB
/
MethodReferenceExample1.java
File metadata and controls
49 lines (32 loc) · 1.28 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
48
49
package unit3;
/**
* Created by byung-chunyoo on 7/16/17.
*/
public class MethodReferenceExample1 {
public static void main (String [] args){
System.out.println("directly execute the method: ");
printMessage();
System.out.println("use anonymous inner class ");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello from inside of anonymous class");
}
});
thread.run();
System.out.println(" ");
System.out.println("Using lambda");
Thread thread1 = new Thread(() -> System.out.println("Hello from inside of lambda"));
thread1.run();
System.out.println(" ");
System.out.println("direct method call from lambda");
Thread thread2 = new Thread(() -> printMessage());//method execution: taking a method and execute it.
thread2.start();//method from Thread class
thread2.run();
//Method reference when no input argument and calling a method with no argument
Thread thread3 = new Thread(MethodReferenceExample1::printMessage);//inside () is the same as () -> printMessage()
}
public static void printMessage(){
System.out.println("Hello");
}
}