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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:40:31+00:00 2026-06-17T05:40:31+00:00

I have classes A , B , C and D where B extends A

  • 0

I have classes A, B, C and D where B extends A, C extends A and D extends A.

I have the following ArrayLists each with a few elements in them:

ArrayList<B> b;
ArrayList<? extends A> mix = b;

I intended for the variable mix to contain elements of type B, C or D. I tried to add an element of type C into mix like this:

mix.add(anElementOfTypeC);

But the IDE doesn’t allow me to do so and it says:

anElementOfTypeC cannot be converted to CAP#1 by method of invocation
conversion where CAP#1 is a fresh type-variable: CAP#1 extends A from
capture of ? extends A

Did I use the <? extends A> correctly? How can I resolve this?

  • 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-17T05:40:32+00:00Added an answer on June 17, 2026 at 5:40 am

    ArrayList<? extends A> means an ArrayList of some unknown type that extends A.
    That type might not be C, so you can’t add a C to the ArrayList.

    In fact, since you don’t know what the ArrayList is supposed to contain, you can’t add anything to the ArrayList.

    If you want an ArrayList that can hold any class that inherits A, use a ArrayList<A>.

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

Sidebar

Related Questions

I have the following classes: public class CollectionCustomClass extends ArrayList<CustomClass> public abstract class CustomClass
I have the following classes: abstract class DTO{ } class SubscriptionDTO extends DTO {
I have 3 classes, let's call them 1, 2, and 3. Class 1 extends
I have the following classes: package models; public class Test extends activejdbc.Model { }
I have the following classes: import play.db.ebean.Model; import javax.persistence.*; @Entity public class A extends
I have some classes which extends a superclass, and in the JSP I want
Is it possible to have multiple classes that inherit/extends same class in Google AppEngine
I have two classes Foo and Bar that Bar extends Foo as below: class
If I have three classes class A class B extends A class C extends
I have two classes, TestA and TestB . TestA extends QObject . I have

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.