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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:12:47+00:00 2026-06-13T10:12:47+00:00

I couldn’t find a good question/title for what I want to do. I’m not

  • 0

I couldn’t find a good question/title for what I want to do. I’m not very familiar with generics, so I have some issues understanding how they work.

Say I have a Map<k,v> class that maps keys to values.

class Map<K,V>{
    public V get(K key){
        //...
    }

    public void set(K key, V v){
        //...
    }
 }

Then, I create two subclasses:

class SuperMap<K,V> extends Map<K,V>{ /* ... */ }
class HyperMap<K,V> extends Map<K,V>{ /* ... */ }

What I want is to create a function that can take any map and print the string representation of each key and value. So I could just:

SuperMap<Unicorn, Horse> unicornsMap = ....;
HyperMap<Pegasus, Horse> pegasusMap = ....;

printMap(unicornsMap);
printMap(pegasusMap);

So, what should be the printMap function signature?

I tried with: void printMap(Map<Object, Horse>) But it doesn’t work:

The method printMap(Map<Object,Horse>) in the type MainClass is not
applicable for the arguments (HyperMap<Pegasus,Horse>)

The method printMap(Map<Object,String>) in the type MainClass is not
applicable for the arguments (SuperMap<Unicorn,Horse>)

  • 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-13T10:12:48+00:00Added an answer on June 13, 2026 at 10:12 am
    printMap(Map<?, Horse>)
    

    or, alternately

    <K> printMap(Map<K, Horse>)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Couldn't think of a more appropriate question title, but I'm looking for some advice
couldn't find my solution. hope you can help. I want to have a url
I couldn't find anything similar to this anywhere. I have an array of pointers
I couldn't find this in the documentation. If I have a complex object in
I couldn't find a suitable title for this. I'm going to express my query
I couldn't find a straight answer to my question and need to know it
Sorry couldn't think of a better title. :) Here goes, I have been pulling
Couldn't find an answer to this question. It must be obvious, but still. I
Couldn't find similar enough question so I'll ask. I'm trying to use facebook log-in
couldn't find a similar topic but this may boil down to not knowing how

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.