-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathAllInOne8.java
More file actions
279 lines (213 loc) · 7.3 KB
/
Copy pathAllInOne8.java
File metadata and controls
279 lines (213 loc) · 7.3 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Source: https://en.wikipedia.org/wiki/Java_syntax
// Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html
// Lambdas
public class Lambdas {
public static void main(String[] args) {
// use predicate composition to remove matching names
List<Name> list = new ArrayList<>();
for (Name name : NAMES) {
list.add(name);
}
Predicate<Name> pred1 = name -> "Sally".equals(name.firstName);
Predicate<Name> pred2 = name -> "Queue".equals(name.lastName);
list.removeIf(pred1.or(pred2));
printNames("Names filtered by predicate:", list.toArray(new Name[list.size()]));
Comparator<Name> com1 = Comparator.comparing((Name name1) -> name1.lastName)
.thenComparing(name2 -> name2.firstName);
Comparator<Name> com2 = Comparator.<Name,String>comparing(name1 -> name1.lastName)
.thenComparing(name2 -> name2.firstName);
// sort array using lambda expression
copy = Arrays.copyOf(NAMES, NAMES.length);
Arrays.sort(copy, (a, b) -> a.compareTo(b));
printNames("Names sorted with lambda expression:", copy);
}
}
class LambdaAndCastWithBounds{
interface I1<T> {
void fn();
}
interface I2 {
void fn();
}
I1<Byte> i1 = (I1<Byte> & Serializable & Cloneable) () -> {
};
I2 i2 = (I2 & Serializable & Cloneable) () -> {
};
}
// Default interface method
interface Formula {
double calculate(int a);
default double sqrt(int a) {
return Math.sqrt(a);
}
}
// Double colon
public class For {
public void bar() {
Function<Computer, Integer> getAge = Computer::getAge;
Integer computerAge = getAge.apply(c1);
Function<Computer, Integer> getAgeAlt = this::getAge;
Function<Computer, Integer> getAgeAlt2 = MyClass.this::getAge;
Function<Computer, Integer> getAgeAlt3 = generate()::getAge;
Function<Computer, Integer> getAgeAlt4 = MyClass.generate()::getAge;
Function<Computer, Integer> getAgeAlt5 = MyClass.twice().nested()::getAge;
Function<Computer, Integer> getAgeAlt6 = twice().nested()::getAge;
Function<Computer, Integer> getAgeAlt7 = this.singletonInstanceMethod::get;
autodetect(this.beans, ((AutodetectCapableMBeanInfoAssembler) this.assembler)::includeBean);
TriFunction <Integer, String, Integer, Computer> c6Function = Computer::new;
Computer c3 = c6Function.apply(2008, "black", 90);
Function <Integer, Computer[]> computerCreator = Computer[]::new;
Computer[] computerArray = computerCreator.apply(5);
}
}
// Type Annotations
public class Annotations {
@Valid
private List<@NotNull String> property;
}
public interface CallableProcessingInterceptor {
default <T> void beforeConcurrentHandling(NativeWebRequest request, Callable<T> task) throws Exception {
}
}
@FunctionalInterface
public interface RouterFunction<T extends ServerResponse> {
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) {
return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction);
}
}
//Instanceof
class InstanceOf{
public static void main(String[] args){
if(args instanceof String[]){
}
if(args instanceof a.String[]){
}
}
}
// Unicode
class Unicode {
public static void main(String[] args) {
System.out.println("A = \uuu0041");
}
}
// More Annotations
public class Annos {
public @interface Dummy4 {
String[] value();
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface Dummy03 {
Dummy3[] value();
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface Dummy01 {
Dummy1[] value();
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Repeatable(Dummy01.class)
public @interface Dummy1 {
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface Dummy2 {
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Repeatable(Dummy03.class)
public @interface Dummy3 {
}
public static @Dummy4("#1")
@Dummy1 @Dummy3 <T extends @Dummy2 @Dummy3 Object>
@Dummy1 @Dummy3 T @Dummy1 @Dummy3 [] foo(@Dummy1 T @Dummy2 @Dummy3 [] arr, @Dummy1 @Dummy3 T @Dummy1 @Dummy3 ... t) {
return (@Dummy1 @Dummy3 T[]) null;
}
public static @Dummy4("")
<@Dummy1 @Dummy2 T extends @Dummy1 @Dummy3 Object>
@Dummy1 @Dummy3 T @Dummy1 @Dummy3 [] @Dummy1 @Dummy2 [] foo2(@Dummy1 T @Dummy2 @Dummy3 [] @Dummy1 @Dummy3 [] arr) {
return (@Dummy1 @Dummy2 T[] @Dummy1 @Dummy2 []) null;
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.METHOD})
public @interface TM1{
}
class Gen<T> { }
class A<@Dummy1 T extends @Dummy1 Gen<@Dummy1 T> >{}
public static <@Dummy3 T> void foo3(T t, Gen<@Dummy1 @Dummy3 ? super @Dummy1 @Dummy3 T> c) {
}
public static <@Dummy3 T> void foo33(T t, Gen<@Dummy1 @Dummy3 ? > c) { }
public static <@Dummy3 T, @Dummy1 S> void foo333(T t, Gen<@Dummy1 @Dummy3 T @Dummy1 [] > c) { }
public static @Dummy3 <@Dummy3 T extends @Dummy3 Gen<@Dummy1 ? super @Dummy1 T>> @Dummy3 T @Dummy3 [] f(@Dummy3 T @Dummy3 ... t) {
return (@Dummy3 T @Dummy3 []) null;
}
interface TI1{
public @TM1 void im01();
public <@Dummy3 T> @TM1 @TM2 T gim01(@TM1 T t);
}
static class Issue2454 {
interface I {
default <T> void fn1() {
}
default <T, S, U> void fn2() {
}
}
class C implements I {
public void test() {
I.super.<Long>fn1(); // fix #2454
I.super.fn1(); //ok
I.super.<List<Integer>, Byte, Map<Long, String>>fn2(); // fix #2454
I.super.fn2(); //ok
}
}
}
}
class Issue1897 {
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface Dum1 {
}
@Target(ElementType.TYPE_USE)
@interface Dum2 {
}
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface Dum3 {
}
abstract class C {
// https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.1
void f(@Dum1 @Dum2 C this) {
}
void d(C this, int i, int j) {
}
void e(C this, int i, int j, int... k) {
}
void c(C this, int... k) {
}
abstract void am(C this);
class D {
class E {
E(Issue1897.C.D D.this) {
}
}
class GE {
<TY> GE(Issue1897.C.D D.this) {
}
}
void b(Issue1897.C.@Dum3 D Issue1897.C.D.this) {
}
void b2(Issue1897.C.@Dum3 D this) {
}
void b3(@Dum1 D this) {
}
}
void b(Issue1897.C Issue1897.C.this) {
}
}
}