-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCallableViaSummary.java
More file actions
31 lines (24 loc) · 934 Bytes
/
CallableViaSummary.java
File metadata and controls
31 lines (24 loc) · 934 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
import java.util.*;
public class CallableViaSummary {
public interface Element {
public void handle(String message);
}
public void main(String[] args) {
List<Element> elements = new ArrayList<>();
List<Element> elements2 = new ArrayList<>();
elements.add(new Element() {
@Override
public void handle(String message) {
System.out.println(message);
}
});
elements.add(message -> System.out.println(message));
// This dispatches to the two added elements because
// the summary of ArrayList causes flow via type tracking.
elements.get(0).handle("Hello, world!");
// This does not dispatch to anything, showing that the
// open-world assumption does not apply
// (and hence that type tracking is necessary above).
elements2.get(0).handle("Hello, world!");
}
}