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]
# 1
Here is the warning message it gives unchecked call to sort(T[], Comparator<? super T> as a member of raw type Array
durgakbea at 2007-7-12 20:57:47 > top of Java-index,Core,Core APIs...
# 2
Your code talks of MyComparator, DefaultChargeComparator and DueDateComparator. None of this makes sense.Show us all of the relevant code and use the [code] tags (see the formatting tips: http://forum.java.sun.com/help.jspa?sec=formatting)
dannyyatesa at 2007-7-12 20:57:47 > top of Java-index,Core,Core APIs...
# 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

durgakbea at 2007-7-12 20:57:47 > top of Java-index,Core,Core APIs...
# 4
You still missed to provide the relevant information. How is DefaultChargeComparator declared?
stefan.schulza at 2007-7-12 20:57:47 > top of Java-index,Core,Core APIs...
# 5
and DueDateComparator?
ejpa at 2007-7-12 20:57:47 > top of Java-index,Core,Core APIs...
# 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

McNeppa at 2007-7-12 20:57:47 > top of Java-index,Core,Core APIs...