I am creating a small Android app and I want to sort an ArrayList…
It is an ArrayList of the class Skill.
I implemented the Comparable interface like this:
Skill = public class(Comparable)
But when I try to sort my arraylist like this:
Collections.sort(fList);
I get this compiler error:
Error 1 (E210) Generic parameter doesn’t validate on “java.lang.Comparable<java.lang.Object>” constraint for “T” C:\Documents and Settings\Jeroen\Mijn documenten\Visual Studio 2010\Projects\org.me.rpassistant\org.me.rpassistant\MainActivity.pas 104 19 org.me.rpassistant
namespace consoleapplication2;
interface
uses
java.util;
type
ConsoleApp = class
public
class method Main(args: array of String);
end;
Skill = class(Comparable)
private
public
property Name: String;
method compareTo(arg1: consoleapplication2.Skill): RemObjects.Oxygene.System.Integer;
property Value: Int32;
end;
implementation
method Skill.compareTo(arg1: consoleapplication2.Skill): RemObjects.Oxygene.System.Integer;
begin
result := Name.compareTo(arg1.Name);
end;
class method ConsoleApp.Main(args: array of String);
begin
var lst := new ArrayList;
Collections.sort(lst);
end;
end.
I wonder why I have to call a static method on a utility class to sort a generic collection?
Why can’t I just call myList.sort();
At some points the .net class lib is MUCH better designed than the Java one…