I am aware that there is number of similar posts. The error, as i understand, means that i should be more specific with types. My code:
import java.util.*;
public class Storefront {
private LinkedList<Item> catalog = new LinkedList<Item>();
public void addItem(String id, String name, String price, String quant) {
Item it = new Item(id, name, price, quant);
catalog.add(it);
}
public Item getItem(int i) {
return (Item)catalog.get(i);
}
public int getSize() {
return catalog.size();
}
//@SuppressWarnings("unchecked")
public void sort() {
Collections.sort(catalog);
}
}
However, I do specify that LinkedList
consists of objects of type Item
. When i compile it with -xlint, i get
warning: unchecked method invocation: method sort in class
Collections is applied to given types
Collections.sort(catalog);
required: List'<'T'>'
found: LinkedList'<'Item'>'
where T is a type-variable:
T extends Comparable'<'? super T'>' declared in method
'<'T'>'sort'<'List'<'T'>'>
As i understand, LinkedList
implements List
and Item
implements Comparable
. So, aren't 'required' and 'found' same?
Also I was checking if catalog.get(i);
is actually an Item (as, some say it may have caused the problem), but it produced the same error.