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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:26:13+00:00 2026-06-09T23:26:13+00:00

New to inheritance and generics so bear with me if my question is stupid:

  • 0

New to inheritance and generics so bear with me if my question is stupid:

I have the following:

public abstract class car {
    private long id;
    private String name;

    public car (long id, String name) {
        this.id = id;
        this.name = name;
    }

    public final long getID(){
        return id;
    }

    public final String getName(){
        return name;
    }
}

public class sedan extends car {
    public sedan(long id, String name) {
        super (id, name);
    }
    ...
}

public class jeep extends car {
    public jeep(long id, String name) {
        super (id, name);
    }
    ...
}

I’m trying to extend the ArrayAdapter for a spinner as follows:

public class DropdownAdapter extends ArrayAdapter<car> {
    private Context context;
    private List<car> values;

    public DropdownAdapter(Context context, int textViewResourceId, List<car> values) {
        super(context, textViewResourceId, values);
        this.context = context;
        this.values = values;
    }
    ...
}

The problem comes when I try to use it:

adapter = new DropdownAdapter (this, android.R.layout.simple_spinner_item, lstSedan);

will give me the error: The constructor DropdownAdapter (ScreenItemList, int, List< sedan >) is undefined

adapter = new DropdownAdapter (this, android.R.layout.simple_spinner_item, lstJeep);

will give me the error: The constructor DropdownAdapter (ScreenItemList, int, List< jeep >) is undefined

What is the issue here? Why can’t I use lstSedan or lstJeep as parameters when they are derived from car? How do I resolve this? Thanks!

  • 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-09T23:26:15+00:00Added an answer on June 9, 2026 at 11:26 pm

    You defined a method that expects a parameter of type List<a>

      public SpinnerAdapter(Context context, int textViewResourceId, List<a> values)
    

    That is, it expects a list of items of type a.
    But then you pass a parameter of type b that inherited a, instead of a parameter of type List<b>
    Try to use this way:

      List<b> lstB= new ArrayList<b>();
      adapter = new SpinnerAdapter (this, android.R.layout.simple_spinner_item, lstB);
    

    As JoxTraex said, you should read java name convention

    Update:
    Sorry, I made a mistake. Because java doesn’t allow passing List<ChildClass> parameter to List<ParentClass>, so you shouldn’t use inheritance in this case. Try using generic

    public class DropdownAdapter extends ArrayAdapter<T> {
    private Context context;
    private List<T> values;
    
    public DropdownAdapter(Context context, int textViewResourceId, List<T> values) {
        super(context, textViewResourceId, values);
        this.context = context;
        this.values = values;
    }
    ...
    }
    

    And this function call should work:

     adapter = new SpinnerAdapter (this, android.R.layout.simple_spinner_item, lstB);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have these classes class SuperParent { @Override public String toString() { return SuperParent;
Say I have the following classes: public class BaseConfig { } public class SpecialConfig
I am trying to create a new class Dog that inherits via prototypical inheritance
I’m fairly new to IoC and perhaps my understanding of generics and inheritance is
//this class (or interface if you like) is set up as generic... public abstract
Using DataNucleus, I have been happy using an abstract base class to provide a
I'm fairly new to NHibernate and have run into a strange inheritance chaining issue
I've something along this lines: public class Something { private IDictionary<object,Activity> fCases; public IDictionary<object,Activity>
I am fairly new to inheritance and wanted to ask something. I have a
Suppose I have an inheritance chain where every class extends its superclass by adding

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.