Collections.sort with Generics

Hi,

I was trying to call collections.sort for a List<MyClass> and I got a warning in eclipse. My code was something like this.

List<MyClass> list = new ArrayList<MyClass>();

/* some code for poluating the list */

Collections.sort(list);

On the above line I got the following warning in eclipse:

Type safety: Unchecked invocation sort (List<MyClass>) of the generic method sort(List<T>) of Type Collections.

Is there anyway I could add the generic class information for this method invocation.

TIA

Gaurav

[597 byte] By [gaurav1146a] at [2007-11-27 1:34:42]
# 1
MyClass needs to be Comparable or you need to provide a Comparator of the appropriate type.
dcmintera at 2007-7-12 0:42:20 > top of Java-index,Java Essentials,Java Programming...
# 2

> MyClass needs to be Comparable or you need to provide

> a Comparator of the appropriate type.

@OP, just a small addition to dcminter's post:

Have a look at this tutorial:

http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html

Good luck.

prometheuzza at 2007-7-12 0:42:20 > top of Java-index,Java Essentials,Java Programming...
# 3
MyClass does implement comparable. Had it not implemented Comparable the code would not have compiled. The problem I mentioned was that I am getting a Type safety warning in eclipse.
gaurav1146a at 2007-7-12 0:42:20 > top of Java-index,Java Essentials,Java Programming...
# 4
You probably get the warning because it implements the raw Comparable type. Have it implement Comparable<MyClass>.
DrClapa at 2007-7-12 0:42:20 > top of Java-index,Java Essentials,Java Programming...
# 5
What do you get running from the command line?
ChuckBinga at 2007-7-12 0:42:20 > top of Java-index,Java Essentials,Java Programming...