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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:33:06+00:00 2026-06-06T16:33:06+00:00

That title’s a little tricky… When I’m writing an interface, is it generally best

  • 0

That title’s a little tricky…
When I’m writing an interface, is it generally best practice to return the most specific interface possible, or least?

For example, suppose

interface List2<T> extends List<T>
{
    List<T> getRange(int startIndex, int endIndex);
}

Would it be better to change it to

interface List2<T> extends List<T>
{
    List2<T> getRange(int startIndex, int endIndex);
}

so that callers can call getRange on their result, while still matching List polymorphically?

  • 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-06T16:33:08+00:00Added an answer on June 6, 2026 at 4:33 pm

    If the code is changing a lot (usually while still in development), I would return the most specific interface, and make it broader when further needs required it. This way, you encourage that the interface is not used too often, and it’s easier to change things if you decide to remove or radically change the interface later.

    If the code is stable, or part of an API to be published, I would return the broadest interface, to make it usable to the largest audience.

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

Sidebar

Related Questions

First of all, sorry about that title. I'm not the best at writing those
OK, that title is a little unclear, but I can't think of a better
OK so that title sucks a little but I could not think of anything
I'm writing a piece of Javascript that takes in the title of the current
Ok, that title is going to be a little bit confusing. Let me try
I know that the title might sound a little contradictory, but what I'm asking
That title is presumably awfully worded. I have some PostgreSQL tables. There is a
That title may need some work. Perhaps after reading this, you may be able
Does that title sound confusing? I thought it might well anyways. When I person
I'm not sure that title is worded very well, but not sure how else

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.