我有以下方法
private ArrayList<User> allUsers = new ArrayList<User>();
public User getUser(int index) {
try {
return allUsers.get(index);
}
catch(IndexOutOfBoundsException e) {
// What should I return here?? Say that you want index 0 and no User
// exists in the ArrayList allUsers, what should I then return? The
// method needs a User to be returned
}
}
而且我不知道该怎么做,我确定这是一个简单的解决方法,但是我应该在 catch 块中返回什么?Eclipse 抱怨User
必须返回 a 。