OnJava8-Examples/generics/ErasureAndInheritance.java

26 lines
630 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: generics/ErasureAndInheritance.java
class GenericBase<T> {
private T element;
public void set(T arg) { element = arg; }
2015-04-20 15:36:01 -07:00
public T get() { return element; }
}
class Derived1<T> extends GenericBase<T> {}
class Derived2 extends GenericBase {} // No warning
// class Derived3 extends GenericBase<?> {}
// Strange error:
// unexpected type found : ?
2015-05-18 23:05:20 -07:00
// required: class or interface without bounds
2015-04-20 15:36:01 -07:00
public class ErasureAndInheritance {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Derived2 d2 = new Derived2();
Object obj = d2.get();
d2.set(obj); // Warning here!
}
2015-05-05 11:20:13 -07:00
} ///:~