-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTest.java
More file actions
77 lines (58 loc) · 1.72 KB
/
Test.java
File metadata and controls
77 lines (58 loc) · 1.72 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class Test {
interface Function<T> {
Object apply(T o) throws Exception;
}
interface IntFunction {
Object apply(int i);
}
interface Supplier {
Object get() throws Exception;
}
public Test() { }
static class BaseClass {
}
static class Generic<T> extends BaseClass {
public Generic() { }
class Inner {
public Inner() { }
void test() {
Supplier s0 = Generic.this::toString;
Supplier s1 = Generic.super::toString;
}
}
void test() {
Supplier s0 = Generic<Number>.Inner::new;
Supplier s1 = super::toString;
}
}
void doSomething() { }
static void staticMethod() { }
static class Sub extends Test {
}
interface SubtypeConsumer {
void consume(Sub s);
}
void test() {
Function<Test> f0 = Test::toString;
Function<Test> f1 = Test::hashCode;
Function<Test> f2 = Test::clone;
Function<Generic<String>> f3 = Generic<String>::toString;
Supplier s0 = this::toString;
Supplier s1 = this::hashCode;
Supplier s2 = this::clone;
Supplier s3 = ((Supplier) this::toString)::toString;
// Discards result of method call
Runnable r0 = this::toString;
Runnable r1 = Test::staticMethod;
Supplier[] classInstances = {
Test::new,
Generic<String>::new,
};
IntFunction[] arrays = {
int[]::new,
Generic[]::new,
};
// SubtypeConsumer has `Sub` as parameter type, but receiver here is `Test` (supertype)
SubtypeConsumer sub = Test::doSomething;
}
}