-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathErasureAndInheritance.java
More file actions
47 lines (35 loc) · 1009 Bytes
/
ErasureAndInheritance.java
File metadata and controls
47 lines (35 loc) · 1009 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package generics;
import java.util.*;
/**
* RUN:
* javac generics/ErasureAndInheritance.java && javac generics.ErasureAndInheritance
* OUTPUT:
*
*/
public class ErasureAndInheritance {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Derived2 d2 = new Derived2();
Object obj = d2.get();
d2.set(obj); // Note: generics\ErasureAndInheritance.java uses unchecked or unsafe operations.
// Note: Recompile with -Xlint:unchecked for details.
}
}
class GenericBase<T> {
private T element;
public void set(T arg) { element =arg; }
public T get() { return element; }
}
class Derived1<T> extends GenericBase<T> {}
class Derived2 extends GenericBase {}
/*
*
* error: unexpected type
* class Derived3 extends GenericBase<?> {}
* ^
* required: class or interface without bounds
* found: ?
* 1 error
*
*/
class Derived3 extends GenericBase<?> {}