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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:05:02+00:00 2026-05-20T02:05:02+00:00

I want to create a kind of in-memory database into which I can put

  • 0

I want to create a kind of in-memory database into which I can put objects of any type that extends EntityProxy. I want to index every object according to its type and id number (which every EntityProxy has – something simple like creating a HashMap for each type.

I could implement this manually with something like

public void put(Object o)
{
    if (o instanceof Car)
        carIndex.put(o.getId(), o);
    else if (o instanceof Bus)
        busIndex.put(o.getId(), o);

    ...
}

But of course I don’t want to. I want something more like

public void <T extends EntityProxy> put(T o)
{
   indexMap.get(o.class).put(o.getId(), o);
}

I just don’t quit have the generics vocabulary to do this. I don’t know what the question mark means in template definitions, really – will something like

HashMap<Class<?>, HashMap<Long, EntityProxy>> indexMap

work?

  • 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-20T02:05:03+00:00Added an answer on May 20, 2026 at 2:05 am

    That map is OK; if you really need to add a tiny bit of constraint, just try:

    Map<Class<? extends EntityProxy>, HashMap<Long, EntityProxy>> indexMap;
    

    This would make sure the key class can only be an EntityProxy.class or subclass.

    You can think of the question mark as some “anything”, but anonymous. So <?> means really anything — any Object, <? extends EntityProxy> means anything that fulfils this condition (passes the “instanceof EntityProxy” test).

    The type safety here is less than desired, as you can still put anything as key and anything in that map. I mean, you can legally put this in the map:

    indexMap.put(EntityProxy1.class, new HashMap<Long, EntityProxy2>());
    

    (assuming EntityProxy1 and EntityProxy2 are both subclasses of EntityProxy) since there’s no correlation between the key and the value. To enforce that, the put() method of the map would need to be declared like this:

    <T extends EntityProxy> put(Class<T> key, HashMap<Long, T> value);
    

    T is pretty much like ? but the main difference is that it provides you with a name that you can refer to it in that context.
    So, if I said that ? stands for “anything”, I would say T stands for “something”, as you can refer to that something once you declare it.

    But you would need a custom data structure for this, as java.util.Map does not provide this kind of constraint. If you’re using it as shown in your code sample, I don’t think you really need these enforcements.

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

Sidebar

Related Questions

I want create wordpress website into which I want create user management... That means
I want to create some kind of AJAX script or call that continuously will
I want to create my own kind of a SeekBar which means I want
I want to create a dialog that contains some kind of text element (JLabel/JTextArea
I want to create an application for the iPhone that plays a custom memory
Im new to android and I want to create kind of CRUD with SQLite.
I want to make this kind of query: create procedure something @name varchar(13) as
i want create a custom json data from the mssql 2008 results so that
I want create an application with animate button? how can i do? after click
I want to implement a high speed in memory implementation of Trie to create

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.