Java-增强代码的安全和健壮性
在传入索引的方法内,做检查索引越界的操作.
if(index < 0 || index >= size){
throw new IllegalArgumentException("索引越界");
}
private static Integer get (int index){
if(index < 0 || index >= size){
throw new IllegalArgumentException("索引越界")
}
return players[index];
}
共有 0 条评论