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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:52:40+00:00 2026-06-09T00:52:40+00:00

If A extends X, the following declaration is valid List<? extends X> list =

  • 0

If A extends X, the following declaration is valid

    List<? extends X> list = new ArrayList<A>();

It seems to be that a list would hold a collection of elements that extend X. As such, new A() should qualify.

Yes, it does not. Why is that?

  • 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-09T00:52:42+00:00Added an answer on June 9, 2026 at 12:52 am

    You’ve almost got it. List<? extends X> means “a list of some type (which I don’t actually know) which is a subtype of X (or possibly X itself)”.

    The problem is if X is, for example, Number. Then List<? extends X> means List<Double> or List<Integer> or some other type, which you’ve just said you don’t actually know. You can’t insert any Number into a List<Integer>. So, since you don’t know the type of the elements of the list, you can’t insert anything into a List<? extends Number>. You can, however, retrieve values from the list, and you are guaranteed that any value contained in the list is at least a Number.

    For more information, read Item 28: Use bounded wildcards to increase API flexibility in Effective Java, 2nd Ed. by Joshua Bloch (a book which every Java programmer should have on their bookshelf). In particular, this item explains the mnemonic PECS, meaning “producer extends, consumer super”, which will help you remember what the extends and super keywords mean in Java generics and when they should be used.

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

Sidebar

Related Questions

the following java class declaration is incorrect: public class BookKeeping<T extends Transaction<K extends Money>>
I have following code that displays an Image with letters, public class MainActivity extends
Let's consider that I want to extend an existing JSF component, such as the
Consider the following Java function: public void foo(Class<? extends Exception> cl, List<? extends Exception>
I have a following JFrame. public class AddActivityWindow extends JFrame { //declaration of components
I'm having some trouble in the following code. public ArrayList<? extends IEvent> getEventsByDateRange(DateTime minStartTime,
I am attempting to override a method declaration within an interface that extends another
Imagine the following scenario: class MyClass extends OtherClass<String>{ String myName; //Whatever } class OtherClass<T>
The following code breaks the Law of Demeter : public class Student extends Person
Consider the following piece of code - class MyThread extends Thread { private int

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.