Mercurial > jhg
changeset 658:d10399f80f4e
javac complained about casts, while eclipse compiler is fine
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 21:09:33 +0200 |
parents | 6334b0267103 |
children | 4fd317a2fecf |
files | src/org/tmatesoft/hg/internal/ArrayHelper.java |
diffstat | 1 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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].