返回的值是接口的实现为什么会通不过?
返回的值是接口的实现为什么会通不过?
public List<IABC> test(){
ArrayList<ABCImpl> al=new ArrayList<ABCImpl>();
return al;
}
返回值al不通过,方法的返回类型List<InterFaceABC>,我返回的正是实现list的arraylist,接口IABC的ABCImpl怎么会通不过。提示说:Type mismatch: cannot convert from ArrayList<ABCImpl> to List<IABC>
[解决办法]
cannot convert from ArrayList<ABCImpl> to List<IABC> 这还不明显吗?
[解决办法]
ArrayList<ABCImpl> al=new ArrayList<ABCImpl>();
改成
ArrayList<IABC> al=new ArrayList<IABC>();
[解决办法]
public List<IABC> test(){
ArrayList<IABC> al=new ArrayList<ABCImpl>();
return al;
}
public List<IABC> test(){
List<IABC> al=new ArrayList<IABC>();
IABC iabc = new ABCImpl();
al.add(iabc);
return al;
} public List<IABC> test(){
return new ArrayList<ICustomerService>();
}?public?List<IABC>?test(){
????????return?new?ArrayList<IABC>();
?}