I read through other questions here and found that when the compiler throws a Cannot find symbol
for Collections.sort(List<T> list)
the problem was most often either...
- It was not passed a
List<T>
List<T>
doesn't implementComparable
- Importation of
java.util.Collection
forgotten
I've done all of those things so I suspect that my implementation is somehow wrong. According to this stack overflow entry and the manual my implementation should be legal so I'm out of ideas. Do the rules change if sort is being passed a List<Item>
?
Comparable Implementation
public abstract class Item implements Comparable<Item>
9 {
...//Fields and constructor omitted
25 @Override
26 public int compareTo(Item i)
27 {
28 // String title = this.title; DEBUG FLAG: delete maybe?
29 return this.title.compareTo(i.title); //Returns a negative value if title < i.title, implements alphabetical order by title
30 }
Call in Library.java (Assumes a properly built TreeMap of LinkedList)
public Collection<Item> itemsForKeyword(String keyword)
25 {
26 List<Item> list;
27 if(keywordDbase.get(keyword) == null) //There is no mapping at specified keyword
28 {
29 list = null;
30 }
31 else if(keywordDbase.get(keyword).isEmpty()) //There is a mapping but it is empty
32 {
33 list = null;
34 }
35 else //There is a list that has at least one item in it
36 {
37 list = keywordDbase.get(keyword); //stores a reference to the LinkedList in list
38 }
39
40 Collections.sort(list); //DEBUG FLAG: Calling sort may be unnecessary
41
42 return list; here
43 }
Error
library/Library.java:40: error: cannot find symbol
Collections.sort(list);
^