What is wrong with
private Map<List<K>, V> multiMap= new HashMap<ArrayList<K>,V>();
The complier says that it Type mismatch: cannot convert from HashMap<ArrayList<K>,V> to Map<List<K>,V>. Do I have to give a specific class of List? Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to write
The values of the generic parameters have to match exactly on both sides (as long as you don’t use wildcards). The reason is that Java Generics do not have contra-/covariance (
HashMap<List>is not a supertype ofHashMap<ArrayList>, althoughListof course is a supertype ofArrayList).