Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6366947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:29:13+00:00 2026-05-25T00:29:13+00:00

Can somebody explain me why this Map<String, List<String>> foo = new HashMap<String, LinkedList<String>>(); generates

  • 0

Can somebody explain me why this

Map<String, List<String>> foo = new HashMap<String, LinkedList<String>>();

generates a type mismatch error ?

Type mismatch: cannot convert from HashMap< String,LinkedList< String>> to Iterators.Map< String,List< String>>

Hashmap implements the Map interface, and LinkedList implements the List interface. Moreover, this

List<String> foo = new LinkedList<String>();

works…

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:29:14+00:00Added an answer on May 25, 2026 at 12:29 am

    Fix this like the following:

    Map<String, List<String>> result = new HashMap<String, List<String>>();

    Pay attention that I changed LinkedList to List in the right side of your assignment.

    You are right that LinkedList implements List. But I think that explanation of this error is not in definition of List but in definition of interface Map<K,V>.

    The left side of your expression says that you want to create Map of String and List, i.e. V is “replaced” by List. Right side uses LinkedList. Although LinkedList implements List it does not work because the definition of Map is not something like Map<K, V extends List>, so compiler requires exact match.

    I am not sure that my description is strict enough, but anyway this is the way to right generics. Really, when you create map of list you do not care about the implementation of List, therefore say HashMap<String, List<String>>. Only when you create instance of List care about its implementation. This will allow you to change the implementation if future without modification of other code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody explain this error? ORA-00054: Resource busy and aquire with NOWAIT specified This
Can somebody explain this entry in web.xml ? When it has to be used
Possible Duplicate: Can somebody explain this Javascript method ? (x = [].reverse)() === window
Based on this answer - how to change classes on click can somebody explain
I'm running a Django app using FastCGI and lighttpd. Can somebody explain me what
Can somebody advise me what this code does and how can I convert it
Lutz Roeder's Reflector, that is. Its obfuscated. I still don't understand this. Can somebody
This is baffling me, maybe somebody can shine the light of education on my
Can somebody point me to a resource that explains how to go about having
Can somebody suggest a good free tool for analyzing .Net memory dumps other than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.