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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:12:28+00:00 2026-05-27T17:12:28+00:00

Using Java 6 SE, I have a class that contains a Vector. There is

  • 0

Using Java 6 SE, I have a class that contains a Vector. There is a class method that simply calls the contained Vector’s addAll() method with the same parameters for each. The Vectors can be of either type “Superclass” or type “Subclass” and I want the addAll() methods to support both. This whole setup might look like this:

public class VectorAContainer(){
    this.vectorA = new Vector<Superclass>();
}

public void addAll(Vector<Superclass> vector){
    this.vectorA.addAll(vector);
}

Then I want to call a line of code like this:

VectorAContainer container = new VectorAContainer();
container.addAll(vectorB); //where vectorB is a Vector<Subclass>

The problem is, Eclipse gives the following error:

“The method addAll(Vector<Superclass>) in the type
VectorAContainer is not applicable for the arguments
(Vector<Subclass>).”

Strangely, I have found that addAll() works if it’s NOT inside of a class:

//No container with an addAll(), calling directly on vectorA
this.vectorA.addAll(vectorB); //No errors!

I don’t see a difference between the two above cases. I would like to get the first way to work because I have a much more elaborate class that contains a Vector like the one above. I would greatly appreciate any help you all could provide!

  • 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-27T17:12:29+00:00Added an answer on May 27, 2026 at 5:12 pm

    You need to accept a covariant generic parameter:

    public void addAll(Collection<? extends Superclass> c)
    

    You can see this in the declaration of addAll:

    boolean addAll(Collection<? extends E> c)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Java. I want to have a setter method of one class that
I have a Java program that opens a file using the RandomAccessFile class. I'd
I am using java language,I have a method that is supposed to return an
I have a file that contains java serialized objects like Vector. I have stored
I have a java class that contains a hash map as a member. This
I have built a web application using Java EE platform that sells one of
I have an activity(say, MyActivity) that contains fragments, and i am using fragmentTransaction.replace(XX,YY) for
I have a class that contains two arraylists which I'm trying to store objects
So my problem is this. I have a class called Globals that contains all
I have a MATLAB class which contains a reference to a java object classdef

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.