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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:31+00:00 2026-05-23T01:08:31+00:00

I have this bit of ( counter-intuitive ) observations about generic wildcard notation used

  • 0

I have this bit of ( counter-intuitive ) observations about generic wildcard notation used in collections.
The purpose of the wildcard notation List<? extends T> is to allow the assignment of a List (of subtypes of T) to the reference of List of ‘? of T’. Its purpose is not to specifically allow the adding of elements of subtypes of T into the List ( of ‘? of T’ ) , which is possible even in a List<T>.

    List<Number> list = new ArrayList<Integer>(); // invalid , List<Integer> is not assignable to List<Number>

    List<Number> list = new ArrayList<Number>() ; // OK

    list.add(new Integer(1)); // valid , '? extends Number' not needed!

    List<? extends Number> list1 = new ArrayList<Integer>();  // Valid , because of notation '? extends Number' 

Is my observation correct ?

  • 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-23T01:08:31+00:00Added an answer on May 23, 2026 at 1:08 am

    Yes, your observation is correct. However, in the case you show, it’s not very useful (you’re electing to ignore useful information about the list). The assignment is more useful when it’s implicit as you call a library function.

    For example, say you had a library function that closed a collection of InputStreams. You could accept a List<InputStream>, but that is unnecessarily restrictive. You could instead do this:

    public void closeAll(Collection<? extends InputStream> streams) {
        for ( InputStream stream : streams ) {
            stream.close();
        }
    }
    

    Now you can pass in a List<FileInputStream> instead.

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

Sidebar

Related Questions

I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
I have this bit of code: function addEmail() { email = $(#email).val(); atime =
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have this bit of script to widen a text box on mouseover and
I have this bit of code I found on the web at the end
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
Well, I have this bit of code that is slowing down the program hugely
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I have this small snippet to change a bit of html when a user
I use this bit of code to feed some data i have parsed from

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.