我的要求是我有一个接口,其中一个方法是声明和两个类实现相同的接口,其中一个类有返回类型Set<object type>
和其他LIST<object type>
...请帮助我纠正代码错误。覆盖在接口中声明的方法的返回类型,其实现在类
这里是下面的示例代码:
报告文件 ---接口
public interface Reportfile
{
public <T> parseReadfile();
}
Masterfile.java ----类一
public class Masterfile implements Reportfile
{
Set<Masterpojo > mset = new TreeSet<Masterpojo>();
public String[] newline = null;
public Set<Masterpojo> parseReadfile()
{
try{
Masterpojo mo = new Masterpojo();
CSVReader mread = new CSVReader(new FileReader(mfile),(delimiter));
while ((newline = mread.readNext()) != null)
{
mo.setmline(newline);
mset.add(mo);
}
}catch(Exception e)
{
log.error("file not found");
}
return mset;
}
}
Transfile .java ---- class 2
public class Transfile implements Reportfile
{
List<Transpojo> tlist = new ArrayList<Transpojo>();
public String[] newline = null;
public List<Transpojo> parseReadfile()
{
try{
Transpojo to = new Transpojo();
CSVReader tread = new CSVReader(new FileReader(Transfile),(delimiter));
while ((newline = tread.readNext()) != null)
{
to.settline(newline);
tlist.add(to);
}
}catch(Exception e)
{
log.error("Transaction file not found");
}
return tlist;
}
}
Masterpojo
public class Masterpojo
{
public String[] mline = null;
public String[] getmline()
{
return mline;
}
public void setmline(String[] mline)
{
this.mline = mline;
}
}
Transpojo
public class Transpojo
{
public String[] tline = null;
public String[] gettline()
{
return tline;
}
public void settline(String[] tline)
{
this.tline = tline;
}
}
我错误等贝洛当我编译在CMD的代码:
Masterfile.java:6: error: Masterfile is not abstract and does not override abstract method <E>parseReadfi
le() in Reportfile
public class Masterfile implements Reportfile
^
where E is a type-variable:
E extends Object declared in method <E>parseReadfile()
Masterfile.java:34: error: parseReadfile() in Masterfile cannot implement <E>parseReadfile() in Reportfil
e
public Set<Masterpojo> parseReadfile()
^
return type Set<Masterpojo> is not compatible with void
where E is a type-variable:
E extends Object declared in method <E>parseReadfile()
Transfile.java:7: error: Transfile is not abstract and does not override abstract method <E>parseReadfile
() in Reportfile
public class Transfile implements Reportfile
^
where E is a type-variable:
E extends Object declared in method <E>parseReadfile()
Transfile.java:33: error: parseReadfile() in Transfile cannot implement <E>parseReadfile() in Reportfile
public List<Transpojo> parseReadfile()
^
return type List<Transpojo> is not compatible with void
where E is a type-variable:
E extends Object declared in method <E>parseReadfile()
4 errors
请你屁股界面的代码 – NecroTheif
...对不起忘了。 ..请看看它.... – Svati
当我编译报告文件,我得到这个错误如下:Reportfile.java:4:错误:预计 公众< T > parseReadfile(); ^ 1错误 –
Svati