Skip to content

jdk8 implements the same default method signature of different interface now got error #22

Description

@yjqg6666

https://github.com/shekhargulati/java8-the-missing-tutorial/blob/master/01-default-static-interface-methods.md

Rule 3: Otherwise, the class has to call the desired implementation unambiguously

Running with
openjdk version "1.8.0_144"
OpenJDK Runtime Environment (Zulu 8.23.0.3-macosx) (build 1.8.0_144-b01)
OpenJDK 64-Bit Server VM (Zulu 8.23.0.3-macosx) (build 25.144-b01, mixed mode)
will got error:
Error:(7, 8) java: class com.example.Test inherits unrelated defaults for test() from types com.example.TestAInterface and com.example.TestBInterface

public interface TestAInterface {
    default String test() {
        System.out.println("in a");
        return "a";
    }
}

public interface TestBInterface {
    default String test() {
        System.out.println("in b");
        return "b";
    }
}

public class Test implements TestAInterface, TestBInterface {
}
class App {
    public static void main(String[] args) {
        Test a = new Test();
        a.test();
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions