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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:31:52+00:00 2026-06-12T11:31:52+00:00

I have a class which I am trying to use to test HashMap and

  • 0

I have a class which I am trying to use to test HashMap and TreeMap, shown below;

public class TestMap<KeyType, ValueType>
{
private Map<KeyType, ValueType> internalMap;

/*
 * Entry point for the application
 */
public static void main( String [ ] args )
{
    TestMap<String, Integer> testHashMap = new TestMap<String,Integer>(new HashMap<String, Integer>());
    testHashMap.test();

    TestMap<String, Integer> testTreeMap = new TestMap<String,Integer>(new TreeMap<String, Integer>());
    testTreeMap.test();
}    

/*
 * Constructor which accepts a generic Map for testing
 */
public TestMap(Map<KeyType, ValueType> m)
{
    this.internalMap = m;
}   

public void test()
{
    try
    {
        //put some values into the Map
        this.internalMap.put("Pittsburgh Steelers", 6);

        this.printMap("Tested Map", this.internalMap);  
    }
    catch (Exception ex)
    {

    }
}

}

In the attempted call to the put() method I am receiving the below error message;

The method put(KeyType, ValueType) in the type Map is not applicable for the arguments (String, int)

I am not receiving any other warnings, and I don’t understand why I am getting this? Isn’t this the entire point of generics? To define generically and implement concretely?

Thanks for any assistance!

  • 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-12T11:31:54+00:00Added an answer on June 12, 2026 at 11:31 am

    The test() method is part of the TestMap class. In any of the TestMap methods, you can only reference the generic type, not any specific type (because this depends on the individual instance). However, you can do this:

    public static void main( String [ ] args )
    {
        TestMap<String, Integer> testHashMap = new TestMap<String,Integer>(new HashMap<String, Integer>());
        testHashMap.internalMap.put("Pittsburgh Steelers", 6);
    
        TestMap<String, Integer> testTreeMap = new TestMap<String,Integer>(new TreeMap<String, Integer>());
        testTreeMap.internalMap.put("Pittsburgh Steelers", 6);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class which have one public method Start , one private method and
I am trying to create downloading progress. I have my class which extends AsyncTask:
I have the following javascript class which I am trying to pass to an
I'm trying to hide window after its startup. I have own window-class which is
I'm trying to validate an ID. I have this class called ManejadorTickets in which
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
I m trying to do a unit test to a class which load and
I'm trying to use haml in my project, I have a controller class and
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class A which extends the Activity class. This class is in package

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.