-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx1RefMainV2.java
More file actions
37 lines (30 loc) · 963 Bytes
/
Copy pathEx1RefMainV2.java
File metadata and controls
37 lines (30 loc) · 963 Bytes
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.start;
import lambda.Procedure;
import java.util.Random;
public class Ex1RefMainV2 {
public static void hello(Procedure procedure){
long startNs = System.nanoTime();
// 코드 조각 시작
procedure.run(); // 다형성을 이용한다.
// 코드 조각 종료
long endNs = System.nanoTime();
System.out.println("실행 시간: " + (endNs - startNs) + "ns");
}
public static void main(String[] args) {
hello(new Procedure() {
@Override
public void run() {
int randomValue = new Random().nextInt(6) + 1;
System.out.println("주사위 = " + randomValue);
}
});
hello(new Procedure() {
@Override
public void run() {
for (int i = 1; i <= 3; i++) {
System.out.println("i = " + i);
}
}
});
}
}