2015-09-07 11:44:36 -06:00
|
|
|
// generics/PlainGenericInheritance.java
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
class GenericSetter<T> { // Not self-bounded
|
|
|
|
void set(T arg){
|
|
|
|
System.out.println("GenericSetter.set(Base)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DerivedGS extends GenericSetter<Base> {
|
|
|
|
void set(Derived derived){
|
|
|
|
System.out.println("DerivedGS.set(Derived)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PlainGenericInheritance {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Base base = new Base();
|
|
|
|
Derived derived = new Derived();
|
|
|
|
DerivedGS dgs = new DerivedGS();
|
|
|
|
dgs.set(derived);
|
|
|
|
dgs.set(base); // Compiles: overloaded, not overridden!
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
DerivedGS.set(Derived)
|
|
|
|
GenericSetter.set(Base)
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|