I have a generic class "SimpleList" (excerpt):
public abstract class SimpleList<T> {
protected List<T> list;
public SimpleList(List<T> list) {
this.list = list;
}
}
And another class "TrackList" that extends it (excerpt):
public class TrackList extends SimpleList {
public TrackList(List<XmlTrack> list) {
super(list);
}
}
In "TrackList" I specify that the list is to hold objects of type "XmlTrack". It seems though, like it's not possible to get an object from that list and access its methods. For example, this won't work:
list.get(0).someMethodSpecificToXmlTrack()
I don't understand why this doesn't work? Isn't the list in "SimpleList" set to only hold "XmlTrack"s?
You need to define it as
public class TrackList extends SimpleList<XmlTrack> {
public TrackList(List<XmlTrack> list) {
super(list);
}
}
Because SimpleList
is generic, but you did not specify a type argument when you extended it.