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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:54:15+00:00 2026-05-20T02:54:15+00:00

This has been bugging me for a while and have yet to find an

  • 0

This has been bugging me for a while and have yet to find an acceptable answer. Assuming a class which is either a subclass or implements an interface why would I use the Parent class or Interface as the Type i.e.

List list = new ArrayList();
Vehicle car = new car();

In terms of the ArrayList this now only gives me access to the List methods. If I have a method that takes a List as a parameter then I can pass either a List or an ArrayList to it as the ArrayList IS A List. Obviously within the method I can only use the List methods but I can’t see a reason to declare it’s type as List. As far as I can see it just restricts me to the methods I’m allow to use elsewhere in the code.

A scenario where List list = new ArrayList() is better than ArrayList list = new ArrayList() would be much appreciated.

  • 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-20T02:54:16+00:00Added an answer on May 20, 2026 at 2:54 am

    Using the interface or parent type is generally recommended if you only need the functionality of the parent type. The idea is to explicitly document that you don’t really care about the implementation, thus making it easier to swap out the concrete class for a different one later.

    A good example are the Java collection classes:

    If you always use List, Set etc. instead of e.g. ArrayList, you can later switch from ArrayList to LinkedList if you find that it gives e.g. better performance. To do that, just change the constructors (you don’t even have to change them all, you can mix). The rest of the code still sees an instance of List and continues working.

    If you actually used ArrayList explicitly, you’d have to change it everywhere it’s used. If you don’t actually need an ArrayList specifically, there’s nothing to be gained from using it over the interface.

    That’s why it’s generally recommended (e.g. in “Effective Java” (J.Bloch), Item 52: “Refer to Objects by their interfaces”.) to only use interfaces if possible.

    Also see this related question: Why classes tend to be defined as interface nowadays?

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

Sidebar

Related Questions

This one has been bugging me for a while now. Is there a way
Being new to test based development, this question has been bugging me. How much
I'm sure this has been asked before, but I can't find it. What are
This has been a problem that I haven't been able to figure out for
This has been an adventure. I started with the looping duplicate query located in
This has been driving me crazy for a few days. Why doesn't the following
This has been troubling me for a few years, and was recently exacerbated by
This has been asked before (question no. 308581) , but that particular question and
This has been confusing me for some time. With the advent of UTF-8 as
I know this has been discussed many times, but I am not sure I

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.