public class InsertionSort {
public static <T extends Comparable<T>> void sort(T[] array) {
for (int indexOfNextToInsert = 1; indexOfNextToInsert < array.length; indexOfNextToInsert++) {
// array from array[0] to array[indexOfNextItemToReposition - 1] is sorted
// now insert array item at "indexOfNextItemToReposition" into
// the sorted left side of array
insert(array, indexOfNextToInsert);
}
}
private static <T extends Comparable<T>> void insert(T[] array, int indexOfNextToInsert) {
T nextValue = array[indexOfNextToInsert];
while (indexOfNextToInsert > 0 && nextValue.compareTo(array[indexOfNextToInsert - 1]) < 0) {
array[indexOfNextToInsert] = array[indexOfNextToInsert - 1];
indexOfNextToInsert--; //<-- I am getting an warning here in eclipse
}
array[indexOfNextToInsert] = nextValue;
}
}
有谁知道如何修复此警告?
答案 0 :(得分:0)
您不应重新分配方法参数。对参数的赋值可能与将其用作output parameter的尝试混淆。进一步讨论:http://sourcemaking.com/refactoring/remove-assignments-to-parameters。