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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:27:32+00:00 2026-06-04T21:27:32+00:00

Sometimes I just don’t get generics. I often use the most generic version of

  • 0

Sometimes I just don’t get generics. I often use the most generic version of the collections in the code. For instance if I need a set of just anything I would write something like:

Set<?> set1 = new HashSet<Object>();

It is allowed by the compiler and why shouldn’t it – Set<?> is a as general as Set<Object> (or even more generic..). However if I use “generics of generics” making it “more generic” just doesn’t work:

Set<Class<?>> singletonSet = new HashSet<Class<Object>>(); // type mismatch

What is going on? Why is Set<Object> assignable to Set<?> and Set<Class<Object>> isn’t assignable to Set<Class<?>>?


I always find a way around these kinds of problems but in this case I really want to know why this isn’t allowed and not a work-around.

  • 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-04T21:27:35+00:00Added an answer on June 4, 2026 at 9:27 pm

    Generics are not covariant in Java. This question may help you:

    java generics covariance

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

Sidebar

Related Questions

I use regexes just often enough to be dangerous. I sometimes am hacking with
Sometimes I need to find some strings inside DB usually it is just host-name
sometimes i use debug code to alert something in javascript (for example, matching something
Occasionally, but more often than I'd like, AJAX calls just don't work in IE
Sometimes when developing using open source software, you need to read it's source code
So, sometimes you just need a list of options for your selects. Is there
Sometimes I need to block access on a website, but I don't want to
I just basically want to add about 20 and sometimes 80 Proximity Alerts with
Sometimes I want to build Python or GCC from scratch just for fun, but
The location text from Twitter could be just about anything. Sometimes Twitter clients set

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.