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

  • Home
  • SEARCH
  • 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 8831907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:24:51+00:00 2026-06-14T08:24:51+00:00

I want to implement such a map, Map<Class<T>, T> m; in which, I can

  • 0

I want to implement such a map,


Map<Class<T>, T> m;

in which, I can get a generic object of type T, given the class of T.

I know you may say, you can wrap a Map<String, Object> and use casting to archive this.

I know this.

But imagine the map is Map<Class<T>, Collection<T>>, in which, the value is a very large collection.

I don’t want to traverse the collection and cast every object, since the collection is too large.

So? what do I do?

  • 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-14T08:24:52+00:00Added an answer on June 14, 2026 at 8:24 am

    I don’t want to traverse the collection and cast every object, since the collection is too large.

    I wouldn’t worry about it because

    • you should never need to do this
    • generics are a compile time check so casting to a generic doesn’t do anything at runtime.

    e.g. If T extends Object, casting a Object to T doesn’t do anything. Similarly cast Collection to Collection<T> doesn’t do anything at runtime.

    But imagine the map is Map<Class<T>, Collection<T>>, in which, the value is a very large collection.

    If you imagine this will do something, casting is not the answer. You may need to convert the contents of the Collection but that is completely different in Java.

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

Sidebar

Related Questions

given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I'm looking for a C++ associative map container type which I can perform multiple
I want to implement a string class which has an option to create the
I want to implement an application which will work as a parser. User will
I am starting to study map-reduce databases. How can one implement a reference in
Being rather new to pure functional programming idiom, I can't get how to implement
I want to implement such a functionality that while in mousedown the cursor crosses
I want to implement functionality such as after the application is distributed, if application
I have a map which contains integer values. i want to re-arange this map
I am a noob to tinyMce. I want to implement tinymce such that deprecated

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.