Java Reference
In-Depth Information
Listing 16-41. A Sample Class That Uses Generic Type Parameters
// GenericSuper.java
package com.jdojo.inheritance;
public class GenericSuper<T> {
public void m1(T a) {
// Code goes here
}
public <P extends Employee> void m2(P a) {
// Code goes here
}
}
When the GenericSuper class is compiled, the erasure transforms the code during compilation and the resulting
code looks as shown in Listing 16-42.
Listing 16-42. The GenericSuper Class Transformed Code During Compilation After Erasure Is Used
// GenericSuper.java
package com.jdojo.inheritance;
public class GenericSuper {
public void m1(Object a) {
// Code goes here
}
public void m2(Employee a) {
// Code goes here
}
}
The GenericSub class in Listing 16-43 inherits the GenericSuper class.
Listing 16-43. A GenericSub Class Inherits from the GenericSuper Class and Overrides m1() and m2() Methods
// GenericSub.java
package com.jdojo.inheritance;
public class GenericSub extends GenericSuper {
public void m1(Object a) {
// Code goes here
}
public void m2(Employee a) {
// Code goes here
}
}
Search WWH ::




Custom Search