0
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;
    }
}

有谁知道如何解决这个警告?

4

1 回答 1

0

您不应该重新分配方法参数。对参数的赋值可能与试图将其用作输出参数相混淆。进一步讨论: http: //sourcemaking.com/refactoring/remove-assignments-to-parameters

于 2013-01-10T21:40:39.040 回答