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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:05:13+00:00 2026-06-14T12:05:13+00:00

Given the types List<?> , List<Object> , List<? super Number> , List<Number> , List<Integer>

  • 0

Given the types List<?>, List<Object>, List<? super Number>, List<Number>, List<Integer>, and List<? extends Number>, I am trying to understand their hierarchy.

I know that List<Integer> is NOT a subtype of List<Number>, even though Integer is indeed a subtype of Number, so I thought that it was instead a subtype of List<? extends Number>.

But List<? extends Number> intuitively seems to be a subtype of List<Number>, which makes List<Integer> a descendant of List<Number> after all, as my idea of it shows:

enter image description here

So, if a type is descended from another, but not directly, is it still a subtype of its ancestor (or I am just wrong in the diagram)? This exercise has also gotten me a bit confused about ? vs. Object…actually, it looks like I might have List<Object> and List<? super Number> mixed up. I guess one of the biggest questions is, “Is ‘everything’ an Object…or is everything a ? ?” Or both…or neither?

  • 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-14T12:05:14+00:00Added an answer on June 14, 2026 at 12:05 pm

    Reason why List<Integer> is not a sub type of List<Number>.

    lets just consider a scenario where a List<Number> accepts List<Integer>(which would practically wouldn’t work).

      List<Integer> listI =new ArrayList<Integer>();
      List<Double>  listD = new ArrayList<Double>();
      method(listI);
      method(listD);
    

    and you have a method which takes List<Number> as an argument.

       public void method(List<Number> list) {
        list.add(new Double()); // would fail if you pass an List<Integer> as Integer is not a super type of Integer.
        list.add(new Integer()); //would fail if you pass an List<Double> as Double is not a subtype of Integer       
        }     
    

    so if your method argument declared as List<number> accepts List<Double> and you try to add an Integer into the list of Double.which is wrong, because Double is not a super type of Integer thus List<Number> is not a sub type List<Integer>.

    now consider the same scenario where List<? extends Number> is a method argument instead of List<Number>

                public void method(List<? extends Number> list) {
                          // list.add(new Double()); 
                          // list.add(new Integer());       
                   }
    

    and now you pass an List<Integer> to this method. if it accepts it and you try to add a Double to list of Integers. BOOM… you just added a Double to List of Integer .

    To give an informal example . consider an Animal supertype with Cat and Dog as subtypes.
    now, you have a method which accepts <? extends Animal> and you pass an Dog to this method. and in the method you try to add an Cat. its adding a wrong type (a CAT) to your Dog, thus **List<Dog>** is not a subtype of List<? extends Animal>

    please let me know if this is not expressive enough.Thanks 🙂

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

Sidebar

Related Questions

I have a List<object> that contains instances of three types GuestbookEntry , Comment and
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
The Java type system supports only invariant types. So a List<String> is not an
Given a list of classes inheriting from this base: class Plugin(object): run_after_plugins = ()
Using EF Code First and given an Entity that contains a List, how can
Why does this work: List<?> list = new LinkedList<Integer>(); while this gives a type
Given the following types private class MyTestDummyClassValidationDef : ValidationDef<MyTestDummyClass> { ... } public class
Given two lists of different types, is it possible to make those types convertible
Given some arbitrary SQL I would like to get the data types of the
For any given type i want to know its default value. In C#, there

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.