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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:59:57+00:00 2026-06-15T19:59:57+00:00

MyClass e = new MyClass(); List<Object> ok = new ArrayList<Object>(); List<? extends Object> ko

  • 0
MyClass e = new MyClass();

List<Object> ok = new ArrayList<Object>();
List<? extends Object> ko = new ArrayList<Object>();

ok.add(e);
ko.add(e); // doesn't compile

Why does it doesn’t compile? MyClass is whatever a subclass of Object…

For information, I get the following message:

The method add(capture#1-of ? extends Object) in the type List<capture#1-of ? extends Object> is not applicable for the arguments (MyClass)
  • 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-15T19:59:58+00:00Added an answer on June 15, 2026 at 7:59 pm

    This is your problem:

    List<? extends Object>
    

    That means “it’s a list of some type T which extends Object, but I don’t care what T is”.

    So this would be valid:

    List<? extends Object> ko = new ArrayList<Banana>();
    

    … but you wouldn’t want:

    ko.add(e);
    

    to compile at that point, would you? Because a MyClass isn’t a Banana.

    See the Java generics FAQ for much more information.

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

Sidebar

Related Questions

List<MyClass> myclassList = (List<MyClass>) rs.get(); TreeSet<MyClass> myclassSet = new TreeSet<MyClass>(myclassList); I don't understand why
I have this: import java.util.ArrayList; public class MyClass { ArrayList list = new ArrayList();
My application uses a list like this: List<MyClass> list = new List<MyClass>(); Using the
i'm trying to do the following using smali: add a private instance ArrayList field
I have a List of classes in my collection like List<MyClass> test = new
I want to do something like following code excerpt in ruby a = MyClass.new
I have an list of objects that contains another object in it. List<MyClass> myClass
Hi I have a list of objects, myclass obj1 = new myclass(); myclass obj2
I'm trying to mock this list: private readonly IList<MyClass> myList = new List<MyClass>(); using
I'm trying to mock this ReadOnlyCollection property: private readonly IList<MyClass> myList = new List<MyClass>();

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.