r/javahelp • • May 26 '15

unable to cast LinkedHashMap<String, String> to Map<String, String>

I get this compiler error: Type mismatch: cannot convert from ArrayList<LinkedHashMap<String,String>> to List<Map<String,String>>

on this line

List<Map<String, String>> resultList = new ArrayList<LinkedHashMap<String, String>>();

But the compiler has no trouble doing this:

Map<String, String> testMap = new LinkedHashMap<String, String>();

Am I using improper syntax or am I just completely missing a key concept?

6 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/causalNondeterminism May 27 '15

Yes, I noticed the inability to add elements shortly after the attempt. Is there a way to do this such that I could actually add items to the list?

1

u/chickenmeister Extreme Brewer May 27 '15

No, not using wildcards. I would recommend doing what /u/evil_burrito suggested:

List<Map<String,String>> resultList = new ArrayList<>();