KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following gives me an error message: public static List<Comparable<?>> merge(Set<List<Comparable<?>>> lists) { List<Comparable<?>> result = new LinkedList<Comparable<?>>(); HashBiMap<List<Comparable<?>>, Integer> location = HashBiMap.create(); int totalSize; for (List<Comparable<?>> l : lists) { location.put(l, 0); totalSize += l.size(); } boolean first; List<Comparable<?>> lowest; //the list with the lowest item to add int index; while (result.size() < totalSize) { first = true; for (List<Comparable<?>> l : lists) { if (! l.isEmpty()) { if (first) { lowest = l; } else if (l.get(location.get(l)).compareTo(lowest.get(location.get(lowest))) <= 0) { //error here lowest = l; } } } index = location.get(lowest); result.add(lowest.get(index)); lowest.remove(index); } return result; } The error is: The method compareTo(capture#1-of ?) in the type Comparable<capture#1-of ?> is not applicable for the arguments (Comparable<capture#2-of ?>) What's going on here? I made the type of everything Comparable so I could call .compareTo and sort this list. Am I using generics incorrectly?
Tags (comma-separated)
Save Edits
Cancel