I have a interface named ReportWriter, which write report to OutputStream, the Report class which contains list of reportRow, the is also an abstract class:
public interface ReportWriter<T extends ReportRow> {
OutputStream writeReport(Report<T> report) throws ReportWriterException;
}
public abstract class Report<T extends ReportRow> {
private List<T> rows = Lists.newArrayList();
...
}
public abstract class ReportRow {...}
Now i have CsvWriter which implement ReportWriter,
public class CsvWriter<T extends ReportRow> implements ReportWriter {
@Override
public ByteArrayOutputStream writeReport(Report report) throws ReportWriterException {
...
for (T row : report.getRows()) { <-- incompatible type
..write here..
}
}
in the above code, it complains incompatible type:
require Object found T.
I dont' understand in Report class I've specified the T is a subclass of ReportRow, why I got this complain?
Then I tried to update the CsvWriter's writeReport as below:
public class CsvWriter<T extends ReportRow> implements ReportWriter {
@Override
public ByteArrayOutputStream writeReport(Report<T> report) throws ReportWriterException { <--- complain here
...
}
now it complained:
writeReport(Report<T> report) clashes with writeReport(Report report); both methods have same erasure.
How can i fix this? thanks