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 8375475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:11:14+00:00 2026-06-09T15:11:14+00:00

I do have troubles manipulating hashmaps. My problem is quite simple, but I cannot

  • 0

I do have troubles manipulating hashmaps. My problem is quite simple, but I cannot make it work…

I have an interface named MultilineWritable. My classes that do need to be marshalled on flat files do implement this interface, which define a String toFlatFormat() function and its opposite init(String flatFormat).

Now imagine that the Contract class do implement MultilineWritable and is identified by integers while the Person class do also implement this interface but is identified by Strings.

My function to marshall the HashMaps of contracts and persons looks like :

public void marshall(HashMap<Object, MultilineWritable>){}

My problem is I cannot find a way to cast a HashMap<String, Person> to a HashMap<Object, MultilineWritable>, even if String extends Object and Person extends MultilineWritable. Same for the casting of a HashMap<Integer, Contract>… consequently I cannot call my generic function.

Thx for any help regarding this problem.

  • 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-06-09T15:11:16+00:00Added an answer on June 9, 2026 at 3:11 pm

    Assuming your marshall method only ever reads values, you should just change the declaration to:

    public void marshall(HashMap<?, ? extends MultilineWritable> map)
    

    The problem is that if the existing method call were allowed, it could try to put any MultilineWritable into the map – even if it was the wrong map type:

    Map<String, Person> map = new HashMap<String, Person>();
    
    // What would you want map.put("foo", new Contact()) to do inside marshall?
    marshall(map);
    

    EDIT: For more details about wildcards, see the Java Generics FAQ.

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

Sidebar

Related Questions

I'm trying to use auto-generated forms in symfony, but I have troubles finding good
I am about to present my work that I have created in MATLAB, but
I have troubles when I perform a UIAlertView, (the alert view works fine) but...
I have troubles with the following database design (simplified for the example). It allows
I have troubles using a foreign protocol in Objective-C. Is there any other solution
I have troubles animating a StackPanel with the VisualStateManager . VisualStateManager.GoToState() accepts a Control
I'm writing an MPI C program. I have troubles debugging it, because whenever I
I have some troubles with my school project. I have a class: #include Group.h
I have some troubles with plotting the figure. I have a file with some
I have some troubles mapping a JSON Array to RestKit. This is what the

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.