I have the class
public class ReportItem<ReportType extends Report>{ }
and the class
public abstract class Report implements Iterable<ReportItem>{
private List<ReportItem<? extends Report> > itemList;
public void add(ReportItem<? extends Report> item){
itemList.add(item);
}
//Some other staff
}
public class ConcreteReport extends Report{
//Some staff
}
The thing is the method add(ReportItem<? extends Report>)
is unsafe in the way I could provide items aren't tied with the current report, but tied with some another and the compiler won't complain.
Is it possible to write the method add
in a type-safe way, i.e. we could pass as an argument only that ReportItem<T>
where T is the type of a current report.