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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:26:38+00:00 2026-06-06T22:26:38+00:00

Consider the following code: public interface A { public A another(); } public interface

  • 0

Consider the following code:

public interface A {
  public A another();
}

public interface B {
  public B another();
}

public interface AB extends A,B {
  public AB another();
}

This leads to a compile error on AB:

types B and A are incompatible; both define another(), but with
unrelated return types

I’ve seen this SO question, and follow the incompatibility example in the the accepted answer – i.e.

public interface C { 
  public void doSomething();
}

public interface D {
  public boolean doSomething();
}

public interface CD extends C,D { 
}

However, in that case the return types were genuinely incompatible – a return type cannot be both void and a boolean. Whereas, in my example above, the another() return type of AB is both an A and a B, so it is possible to implement both of the extended interfaces.

Furthermore, having looked at the JLS (8.4.8, 8.4.8.3, 8.4.8.4), I don’t quite understand why my example above illegal. Can anyone explain this to me?

Second, are there any solutions/workarounds to this other than repeating the contract requirements of A or B in AB?

  • 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-06T22:26:40+00:00Added an answer on June 6, 2026 at 10:26 pm

    This error message appears for pre 1.5 versions of Java (at least I can reproduce the error when setting the compliance level to 1.4 in Eclipse). In other words, make sure you’re looking at old-enough specs.

    On Java >= 1.5 the following compiles fine.

    interface A {
        public A another();
    }
    
    interface B {
        public B another();
    }
    
    interface AB extends A,B {
        public AB another();
    }
    

    As you say, since AB is both an A and a B, it satisfies both interfaces.


    Here’s a quote from the Java Language Specification (Second Edition, i.e. Java 1.4):

    9.2 Interface Members

    The members of an interface are:

    • Those members declared in the interface.
    • Those members inherited from direct superinterfaces.
    • If an interface has no direct superinterfaces, […]

    It follows that it is a compile-time error if the interface declares a method with the same signature and different return type or incompatible throws clause.

    Further more, the current spec says the following:

    9.4.2 Overloading

    If two methods of an interface (whether both declared in the same interface, or both inherited by an interface, or one declared and one inherited) have the same name but different signatures that are not override-equivalent (§8.4.2), then the method name is said to be overloaded. This fact causes no difficulty and never of itself results in a compile-time error. There is no required relationship between the return types or between the throws clauses of two methods with the same name but different signatures that are not override-equivalent.

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

Sidebar

Related Questions

Consider this code: public interface Foo extends Comparable<Foo> {} public enum FooImpl implements Foo
Consider the following code. public interface IFoo { } public class Bar { public
Consider the following lines of code: public interface IProduct { string Name { get;
consider the following code: public class SynchronizedCounter extends Thread { private int c =
Let's consider the following code: public class MyPanel extends JPanel { private long secretInfo
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
Consider the following code: public class MyClass { public static string MyStaticMethod() { //string
Please consider the following code: public class Person ( public string FirstName {get; set;}
Consider the following code: class A { public: virtual void f() throw ( int
Consider the following code: class A { public: A& operator=( const A& ); const

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.