-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathGeneric11.java
51 lines (44 loc) · 1.09 KB
/
Generic11.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
class Generic11 {
interface I<T> {
void set(T e);
}
static class A implements I<String> {
public void set(String e) {
System.out.println("setting " + e);
}
}
static class E implements I<String> {
public void set(Integer n) {
System.out.println("integer " + n);
}
public void set(String s) {
System.out.println("string " + s);
}
}
static class B<T> {
void f(T t) {}
}
static class C extends B<Integer> {
void f(Integer n) {
System.out.println(n);
}
}
static class D extends B<String> {
void f(Integer n) {
System.out.println("integer " + n);
}
void f(String s) {
System.out.println("string " + s);
}
}
public static void main(String[] args) {
System.out.println("begin");
new A().set("hello");
new C().f(42);
new D().f(43);
new D().f("d");
((B) new D()).f("cast to raw");
new E().set(44);
new E().set("e");
}
}