我的方法出现了stackoverflow错误,我不知道为什么,因为我的
if (index < elements.size())
行确保它不是无限递归调用。到目前为止这是我的代码。
private boolean checkIfIncreasing(ArrayList<T> elements, int index){
index = 0;
boolean currentReturnVal = false;
//element at position 0 of the passed in array
T objAtIndex = elements.get(index);
//element at position 1 of the passed in array
T objAtNextIndex = elements.get(index + 1);
//if the size is 1 then just return true bc its the only element in there
if (elements.size() == 1){ currentReturnVal = true;}
if (index < elements.size()){ //takes care of non infinite "looping"
//checks to see if obj at index 0 is less than or equal to obj 1
if (objAtIndex.compareTo(objAtNextIndex) <= 0){
currentReturnVal = true;}
checkIfIncreasing(elements, index++);
if (objAtIndex.compareTo(objAtNextIndex) >= 0){
return false; }
}
return currentReturnVal;
}
我不知道为什么我收到错误