问题是是否应该抛出异常或预防它发生。 这是一个游戏项目。
IndexOutOfBoundsException与编码绕过它。
我有一个List。
通过索引获取项目的方法。
在这种情况下,我将默认使用列表的第一个元素。
IndexOutOfBoundsException与编码绕过它。
我有一个List。
private Attribute<List> attributes;
通过索引获取项目的方法。
public Attribute getAttribute (int index) {
if (index < 0 || index >= attributes.size())
index = 0;
return attributes.get(index);
}
在这种情况下,我将默认使用列表的第一个元素。
IndexOutOfBoundsException when choosing weapon. Please report to game admins.
我永远不会再玩这样的游戏了。 - Luiggi MendozagetAttribute
可能被调用时传入的index
不在0和attributes.size()
之间,则说明您的代码中存在其他错误需要修复。在此争论是否应该在此处抛出异常有点毫无意义。 - Dawood ibn Kareem