You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
@yjqg6666 If you have 2 different interfaces, and they both have a default method with the same signature, and you try to implement both of those interfaces in the same class, you will get a compile time error - as you have demonstrated.
This has always been an issue for interfaces (2 interfaces with identical method signatures can't be implemented in the same class). Default methods aren't really any different in this regard. Default methods are still public signatures on the interface - they just happen to have some behaviour attached to them now.
I'm not sure if that's what you are trying to point out, or if you have a different issue. Can you clarify some?
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
The text was updated successfully, but these errors were encountered: