I have a method for sorting a List of composite Entry objects with Integer key and any type for the value. It has the following signature:
static void bucketSort(List<Entry<Integer, ?>> list, int n)
{
//some code
}
Where the entry interface is as follows:
interface Entry<K, V> {
K getKey(); //returns key stored in this entry
V getValue(); //returns the value stored in this entry
}
However, even though, in my understanding any object can be passed for the "?", this code generates a compile error ("cannot resolve method") in the second line:
List<Entry<Integer, String>> list = new ArrayList<>();
bucketSort(list, 100);
Also, this code gives no error:
List<Entry<Integer, ?>> list = new ArrayList<>();
bucketSort(list, 100);
Can anyone please help me understand why this is? And also, what is the recommended way to resolve the issue?