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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:23:22+00:00 2026-05-17T15:23:22+00:00

I went through these topics Generics..? Super T Bounding generics with ‘super’ keyword However,

  • 0

I went through these topics

  • Generics..? Super T
  • Bounding generics with ‘super’ keyword

However, I still seem to be kind of lost with super keyword:

  1. When we declare a collection like that:

    List<? super Number> list = null;
    list.add(new Integer(0)); // this compiles
    list.add(new Object()); // this doesn't compile
    

shouldn’t it be the opposite – we have a list that contains some objects (of unknown type) which are parents of Number. So Object should fit (since it is the parent of Number), and Integer shouldn’t. The opposite is the case for some reason.

  1. Provided we have the following code

    static void test(List<? super Number> param) {
      param.add(new Integer(2));
    }
    
    public static void main(String[] args) {
      List<String> sList = new ArrayList<String>();
      test(sList);            // will never compile, however...
    }
    

It is impossible to compile the above code (and my sanity suggests that this is the right behaviour), but the basic logic could prove the opposite:

String is Object, Object is superclass of Number. So String should work.

I know this is crazy but isn’t this the reason why they didn’t allow <S super T> constructs? If yes, then why <? super T> is allowed?

Could someone help me restore the missing part of this logic chain?

  • 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-17T15:23:23+00:00Added an answer on May 17, 2026 at 3:23 pm

    The bounded wildcard in List<? super Number> can capture Number and any of its supertypes. Since Number extends Object implements Serializable, this means that the only types that are currently capture-convertible by List<? super Number> are:

    • List<Number>
    • List<Object>
    • List<Serializable>

    Note that you can add(Integer.valueOf(0)) to any of the above types. however, you CAN’T add(new Object()) to a List<Number> or a List<Serializable>, since that violates the generic type safety rule.

    Hence it is NOT true that you can add any supertype of Number to a List<? super Number>; that’s simply not how bounded wildcard and capture conversion work. You don’t declare a List<? super Number> because you may want to add an Object to it (you can’t!); you do because you want to add Number objects to it (i.e. it’s a “consumer” of Number), and simply a List<Number> is too restrictive.

    References

    • Angelika Langer’s Generics FAQs
      • What is a bounded wildcard?
      • When would I use a wildcard parameterized type with a lower bound? (“When a concrete parameterized type would be too restrictive.”)
      • Why is there no lower bound for type parameters? (“Because it does not make sense.”)
    • JLS 5.1.10 Capture Conversion

    See also

    • Effective Java 2nd Edition, Item 28: Use bounded wildcards to increase API flexibility
      • “PECS stands for producer-extends, consumer-super

    Related questions

    • Too many to list, PECS, new Integer(0) vs valueOf, etc
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I went through these topics for a solution to my problem but I think
I went through these instructions: http://docs.amazonwebservices.com/AmazonRDS/latest/GettingStartedGuide/ But still can't connect to the database using
I went through answers on similar topics here on SO but could't find a
I went through all the questions on SOF and did my homework but still
I went through a period of being interested in how quantum computers work and
I just went through some MVC tutorials after checking this site out for a
I recently started learning Emacs . I went through the tutorial, read some introductory
I went through a custom profile provider example a while ago and I am
During the localization of my app I went through a lot of documentation, somewhere
We are currently looking into the Agile Platform by Outsystems. We have went through

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.