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

The Archive Base Latest Questions

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

I had an interface initially as below. public interface testMe { public Set<String> doSomething();

  • 0

I had an interface initially as below.

public interface testMe {
      public Set<String> doSomething();
}
public class A implements testMe {
      public Set<String> doSomething() {
           return // Set<String>
      }
}

I had similar classes implementing testMe. Now I have to add one more class which returns Set<Some Object>

public class X implements testMe() {
     public Set<Some OBject> doSomething() {
     }
}

How could i add this method in the interface without breaking existing classes?

  • 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-15T02:03:05+00:00Added an answer on May 15, 2026 at 2:03 am

    You can’t for two reasons.

    1. A class or interface can’t have two or more methods that have the same number and type of parameters with the same name but differing return types; and

    2. Because of type erasure, all Set<...> instances are, at runtime, simply Set, so they would have the exact same return type anyway.

    You will need to name the second something different.

    The more complicated answer is that you can make the parameter type extensible:

    public interface TestMe<T extends Serializable> {
      Set<T> doSomething();
    }
    
    public class A implements TestMe<String> {
      @Override
      public Set<String> doSomething() { ... }
    }
    
    public class X implements TestMe<ASerializableObject> {
      @Override
      public Set<ASerializableObject> doSomething() { ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

interface Intf { } class A implements Intf { } class Test { public
When I started I had an interface: public interface IBlogReader { BlogPost GetLatest(); IEnumerable<BlogPost>
I am using Pyme to interface with GPGME and have had no problems signing
A question was raised in a discussion I had around whether an interface method
I had two separate interfaces, one 'MultiLingual' for choosing language of text to return,
Had a good read through similar topics but I can't quite a) find one
I just had a long debug session that was caused by a stale interface
I am making a user interface which shows graphs and manipulates graphs. The class
I had this problem initially, so I tried npm install --force It seems to
Can I create anonymous implementations of an interface , in a way similar to

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.