# HG changeset patch # User Artem Tikhomirov <tikhomirov.artem@gmail.com> # Date 1372964973 -7200 # Node ID d10399f80f4ed3aa9838f0a9ebffb277eb3fc49b # Parent 6334b026710381f62e2ab64c97d868542f4e92af javac complained about casts, while eclipse compiler is fine diff -r 6334b0267103 -r d10399f80f4e src/org/tmatesoft/hg/internal/ArrayHelper.java --- a/src/org/tmatesoft/hg/internal/ArrayHelper.java Thu Jul 04 20:27:45 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/ArrayHelper.java Thu Jul 04 21:09:33 2013 +0200 @@ -110,8 +110,7 @@ * Slightly modified version of Arrays.sort1(int[], int, int) quicksort alg (just to deal with Object[]) */ private void sort1(int off, int len) { - @SuppressWarnings("unchecked") - Comparable<Object>[] x = (Comparable<Object>[]) sorted; + Comparable<Object>[] x = comparableSorted(); // Insertion sort on smallest arrays if (len < 7) { for (int i=off; i<len+off; i++) @@ -178,12 +177,22 @@ * Returns the index of the median of the three indexed integers. */ private int med3(int a, int b, int c) { - @SuppressWarnings("unchecked") - Comparable<Object>[] x = (Comparable<Object>[]) sorted; + Comparable<Object>[] x = comparableSorted(); return (x[a].compareTo(x[b]) < 0 ? (x[b].compareTo(x[c]) < 0 ? b : x[a].compareTo(x[c]) < 0 ? c : a) : (x[b].compareTo(x[c]) > 0 ? b : x[a].compareTo(x[c]) > 0 ? c : a)); } + + private Comparable<Object>[] comparableSorted() { + // Comparable<Object>[] x = (Comparable<Object>[]) sorted + // eclipse compiler is ok with the line above, while javac doesn't understand it: + // inconvertible types found : T[] required: java.lang.Comparable<java.lang.Object>[] + // so need to add another step + Comparable<?>[] oo = sorted; + @SuppressWarnings("unchecked") + Comparable<Object>[] x = (Comparable<Object>[]) oo; + return x; + } /** * Swaps x[a] with x[b].