我有下面的方法,它期望返回类型为 SomeObject。mapData() 函数返回 SomeObject。一旦满足一个条件,我就想退出循环。由于未找到返回类型,我收到编译错误。你能指出我的情况的问题吗?
public static SomeObject mapper(List<String> mylist) {
Iterator iter = mylist.iterator();
while (iter.hasNext()) {
Object[] result = (Object[]) iter.next();
if (condition){
//dosomething
return mapData(abc);
}else if (condition) {
//dosomething
return mapData(def);
}else {
//dosomething
return mapData(ghi);
}
}
// Get compilation error due to no return type at this position
}