sort method of Arrays class shows a unchecked warning
HI ,
I am calling the method "sort(T[] ts, java.util.Comparator<? super T> comparator)" of Arrays class. I have overriden the comparator class called MyComparator with the following declaration.
public class MyComparator<C extends Charge> extends
DefaultChargeComparator {
public static final String COMPARATOR_NAME = "Due Date";
public Comparable getComparable(Charge charge) {
return new CalendarDate(charge.getDueDate());
}
public String toString() {
return COMPARATOR_NAME;
}
}
and i am invoking the method
Charge[] openCharges = getOpenCharges(currentBs);
Arrays.sort(openCharges, new com.idsgrp.profinia.payment.comparator.DueDateComparator<Charge>());
Thus i am passing the comparator of type 'Charge' as required by the sort method of Arrays class.
I still have the warning message shown. Please let me know any one know the reason.
Durga
[979 byte] By [
durgakbea] at [2007-11-27 8:49:08]

# 3
well. Here is the complete MyComparator class
public class MyComparator<C extends Charge> extends DefaultChargeComparator {
public static final String COMPARATOR_NAME = "Due Date";
public Comparable getComparable(Charge charge) {
return new CalendarDate(charge.getDueDate());
}
public String toString() {
return COMPARATOR_NAME;
}
}
This is the Client code invoking sort method of Arrays.
Charge[] openCharges = getOpenCharges(currentBs);
Arrays.sort(openCharges, new com.idsgrp.profinia.payment.comparator.MyComparator<Charge>());
Below is the warning message that I like to get rid
unchecked call to sort(T[], Comparator<? super T> as a member of raw type Array
# 6
> unchecked call to sort(T[], Comparator<? super T> as
> a member of raw type Array
There is no type "Array" involved anywhere in your code. It's "Arrays", so you either pasted the wrong error message into your post or you spelled it wrong.
Anyway, if the message were indeed related to "Arrays.sort()", it would be totally misleading. "Arrays" is a non-generic class, thus it cannot be used as a raw type. What compiler are you using?
A sensible message should read something like:
Unchecked invocation sort(Object[], Comparator) of the generic method sort(T[], Comparator<? super T>) of type Arrays
The reason for this warning is probably that the Comparator you're passing to "sort" is derived from the raw type "java.util.Comparator" indirectly via the base class "DefaultChargeComparator".
Either this class is non-generic or you forgot to propagate the type parameter "C" from "MyComparator" to "DefaultChargeComparator".
> well. Here is the complete MyComparator class
>
>
> public class MyComparator<C extends Charge> extends
> DefaultChargeComparator {
> public static final String COMPARATOR_NAME = "Due
> Date";
>
>public Comparable getComparable(Charge charge) {
>return new CalendarDate(charge.getDueDate());
> }
>
>public String toString() {
>return COMPARATOR_NAME;
> }
>
>}
> code]
>
> This is the Client code invoking sort method of
> Arrays.
>
> [code]
> Charge[] openCharges = getOpenCharges(currentBs);
> Arrays.sort(openCharges, new
> com.idsgrp.profinia.payment.comparator.MyComparator<Ch
> arge>());
>
>
>
> Below is the warning message that I like to get rid
>
> unchecked call to sort(T[], Comparator<? super T> as
> a member of raw type Array