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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:30:28+00:00 2026-06-10T03:30:28+00:00

Possible Duplicate: Adding an element inside a wildcard type ArrayList I can’t understand why

  • 0

Possible Duplicate:
Adding an element inside a wildcard type ArrayList

I can’t understand why compiler considers this code wrong:

Pair<Manager> managerBuddies = new Pair<Manager>(ceo, cfo);
Pair<? extends Employee> wildcardBuddies = managerBuddies; // OK
wildcardBuddies.setFirst(lowlyEmployee); // compile-time error

Methods that Pair<? extends Employee> has are:

? extends Employee getFirst()
void setFirst(? extends Employee)

It’s not clear why we can’t set value, because Employee is subtype of ? extends Employee.
Java tutorial tries to explains it, but I still have my question.
Could someone clarify please?

  • 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-10T03:30:30+00:00Added an answer on June 10, 2026 at 3:30 am

    For the compiler, this ? extends Employee means one particular subtype of Employee, and the compiler has no way of detecting which subtype that is. So it can’t allow you to insert just any Employee.

    For more info refer to this question:
    What is PECS (Producer Extends Consumer Super)?
    or read the Generics FAQ by Angelika Langer.

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

Sidebar

Related Questions

Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Python: Adding element to list while iterating This doesn't seem to work,
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: adding media element in windows phone 7? I Want Details Explanation and
Possible Duplicate: How can I get the name of function inside a JavaScript function?
Possible Duplicate: Concurrent Modification Exception : adding to an ArrayList I'm attempting to remove
Possible Duplicate: Dynamically adding collapsible elements I've seen a few posts on this but
Possible Duplicate: Adding label and text box control to GUI Can someone help me
Possible Duplicate: Adding enum type to a list I have an enum class: public
Possible Duplicate: Adding a tuple to a set does not work I have this

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.