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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:54:36+00:00 2026-06-11T15:54:36+00:00

I have an interface A: interface A { } Then I have a class

  • 0

I have an interface A:

interface A {
}

Then I have a class B:

class B implements A {
}

Then I have a method that uses a list of A:

void process(ArrayList<A> myList) {
}

I want to pass it a list of B:

ArrayList<B> items = new ArrayList<B>();
items.add(new B());
process(items);

But then there is an error that types do not match. I understand why. ArrayList is a type itself and it has not function to convert from ArrayList<B> to ArrayList<A>. Is there a quick and resource-wise light way to form a new array that is suitable to be passed to my process method?

  • 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-11T15:54:37+00:00Added an answer on June 11, 2026 at 3:54 pm

    I think the easiest solution is to change one of the methods to:

    void process(ArrayList<? extends A> myList) {
    }
    

    However, be aware that with this solution the entire list needs to be of the same type. That is, if you would have a class C that also would implement A, you can’t mix the items in the array so that parts of it are of type B and parts of it are of type C.

    Also, as pointed out in the comments below, you will not be able to add an object to the list from within this method.

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

Sidebar

Related Questions

I have a C# interface, and a concrete class that implements that interface. I
I have a class that implements a linked list. The class has a find()
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have an interface that has about 20 methods (huge). I want to create
I'm using MooseX::Declare and methods, which uses MooseX::Method::Signatures. Let's say I have a class
I have an interface(call it as IMessage) which has a method Check(), a class
I have a generic class that implements IList public class ListBase<T>: IList<T>, IListBase{ IEnumerator<T>
Say i have an interface I with method doIt(); Now i have a class
I have an interface Node that asks for the method: public HashSet getNeighbour(); NodeVariable
I have an interface IAction that has one generic method: public interface IAction {

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.