What is the EXACT type of your list?
According to the API specs the elements of the List should all be the same type and all must implement Comparable.
If that's not the case you can indeed get that error, as you're passing it an argument that doesn't conform to the specification.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
I can't spot anything really wrong, but you could try importing this:
import java.util.Collections.*;
and see if that works.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Collections is a class inside java.util, so it's imported.
The problem is that he declared his List as List and Object doesn't implement Comparable.
As a result Collections.sort(Collection) isn't going to work because it's being passed a Collection which is not of type Collection.
Had he declared his List as he should have, List = new LinkedList it would have compiled correctly and he'd have the typesafety of generics at the same time instead of just a dirty hack to prevent compiler warnings.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
no, it's the cast you're doing. You don't need that if you properly use generics.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337