So I have an interface
public interface Identity {
abstract void setKey(String key);
abstract String getKey();
}
That I want to use for an insert sort function
public static void InsertIdentity(Identity identity, ArrayList<? extends Identity> list) {
int i = 0;
Identity id;
while (i < list.size()) {
if ((id = list.get(i)).getKey().compareTo(identity.getKey()) < 0) {
i++;
}else{break;}
}
list.add(i, identity);
}
But obviously I cannot add an Identity to a ArrayList - ? extends Identity
I was wondering if there is a way around this?
I know Java has other ways of doing this task but I would like this function to work.