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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:50:37+00:00 2026-06-16T16:50:37+00:00

Possible Duplicate: java generics super keyword I am not able to relate my knowledge

  • 0

Possible Duplicate:
java generics super keyword

I am not able to relate my knowledge with the below sample program. Please see the below sample program then my doubts are below that program.

import java.util.*;
class A { }
class B extends A { }
class C extends B { }

public class sampleprog {

    public static void main(String[] args) {

        List<? super A> list1 = new ArrayList<A>();
        list1.add(new A());//valid. ok
        list1.add(new B());//valid, why? it is not super to A?
        list1.add(new C());//valid, why? it is not super to A?

        List<? super B> list2 = new ArrayList<A>();
        list2.add(new A());//not valid. why? it is also super to B!!!
        list2.add(new B());
        list2.add(new C());

        List<? super C> list3 = new ArrayList<C>();
        list3.add(new A());//not valid, why? It is super to A so should be valid!!!
        list3.add(new B());//not valid, why? It is super to A so should be valid!!!
        list3.add(new C());
    }
}

My Doubts:
– As far as I know ? super T means any class you can add that is super to T but here output is different? Even subclass also added successfully that is totally confusing.
– output is not different with list initialization (List<? super C> list3 = new ArrayList<C>();) . In this initialization, I assigned list of A or B, output was same!

Please clear my doubts.

  • 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-16T16:50:39+00:00Added an answer on June 16, 2026 at 4:50 pm

    “? super T” means any class you can add that must be an instance of T or its sub class.

    So List<? super C> list3 = new ArrayList<C>(); in the list3 either you can add instance of class C or its sub class instances (SomeClass extends C).

    A parent object list can have its own, child and child of child but a List that has created for a child class can not have its parent object. Hope you are clear now.

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

Sidebar

Related Questions

Possible Duplicate: Java Generics Hi, Can anyone please explain the difference of the three
Possible Duplicate: Java Generics To be more specific, whats the role of the <String>
Possible Duplicate: Java Full Screen Program (Swing) -Tab/ALT F4 I've got a full screen
Possible Duplicate: Java Generics: Cannot cast List<SubClass> to List<SuperClass>? I want to create function
Possible Duplicate: Java Generics In Eclipse, I am given warnings for using 'rawtypes' and
Possible Duplicate: Is List<Dog> a subclass of List<Animal>? Why aren't Java's generics implicitly polymorphic?
Possible Duplicate: Is `List<Dog>` a subclass of `List<Animal>`? Why aren’t Java’s generics implicitly polymorphic?
Possible Duplicate: Is List<Dog> a subclass of List<Animal> ? Why aren't Java's generics implicitly
Possible Duplicate: Is List&lt;Dog&gt; a subclass of List&lt;Animal&gt; ? Why aren't Java's generics implicitly
Possible Duplicate: Java Generics, how to avoid unchecked assignment warning when using class hierarchy?

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.