-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathex.java
More file actions
34 lines (20 loc) · 849 Bytes
/
ex.java
File metadata and controls
34 lines (20 loc) · 849 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
import java.util.*;
import java.util.concurrent.*;
class ex {
public static void main(String[] args) {
ExecutorService e = Executors.newCachedThreadPool();
// compile-error because both submit and println are overloaded
e.submit(System.out::println);
// assign to a variable of static type Runnable to resolve ambiguity
Runnable r = System.out::println;
e.submit(r);
// cast to Runnable to resolve ambiguity
e.submit((Runnable) System.out::println);
// examples where arguments are not overloaded
// yield takes 0 input and returns 0 output, i.e. is a Runnable
e.submit(Thread::yield);
// currentThread takes 0 and returns 1 output, i.e. is a Callable
e.submit(Thread::currentThread);
e.shutdown();
}
}