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 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 problem has been bugging me for a while. I have to load a
This one has been bugging me for a while now. Is there a way
This is a question that has been bugging me for a while. I started
This Jquery problem has been bugging me for a while now. I developed a
This is something that has been bugging me for a while as it is
This is one thing that has been bugging me for a while about DDD.
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 optimzation question has been bugging me for the last day. In my program
This has been bugging me for a long time now and I can't seem

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.