-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.java
55 lines (40 loc) · 1.42 KB
/
Example.java
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
package com.trl.theoreticalKnowledge.generics.wildcardUpperBound.methods.returnValue.a.a1;
import java.util.ArrayList;
import java.util.List;
public class Example {
public static List<? extends Father> someMethod_1() {
return new ArrayList();
}
// public static List<? extends Father> someMethod_2() {
// return new ArrayList<Object>(); // Compilation ERROR !!!
// }
// public static List<? extends Father> someMethod_3() {
// return new ArrayList<Grandfather>(); // Compilation ERROR !!!
// }
public static List<? extends Father> someMethod_4() {
return new ArrayList<Father>();
}
public static List<? extends Father> someMethod_5() {
return new ArrayList<Son>();
}
public static List<? extends Father> someMethod_6() {
return new ArrayList<Grandson>();
}
public static <T> List<? extends T> someMethod_7() {
return new ArrayList<T>();
}
// public static <T> List<T extends Father> someMethod_8() { // Compilation ERROR !!!
// return new ArrayList<T>();
// }
public static <T> List<? extends Father> someMethod_9() {
return new ArrayList<Father>();
}
}
class Grandfather {
}
class Father extends Grandfather {
}
class Son extends Father {
}
class Grandson extends Son {
}