Hello,
I am new to generics and trying to change our existing code to use generics.
We have one abstract super class and multiple sub classes. Super class contains a collection that should contain values only of a specific type bases on the sub class. Question I have is, how do I tell super class what type to use for that collection?
Here is the sample code.
Super Class:
import java.util.ArrayList;
import java.util.List;
public class BusinessModelObjectCollection <T>{
private List <T> bmoColl;
public <T> BusinessModelObjectCollection(){
bmoColl = new ArrayList<>();
}
}
Sub Class:
public class AssignableWorkTypeCollection extends BusinessModelObjectCollection {
public AssignableWorkTypeCollection(){
super<AssignableWorkTypeCollection>();
}
}
I am getting compile time error in subclass when I try to pass the type when I call the constructor.
I will really appreciate your help on this.
Thanks,
Swetal