Super class method and Interface default method conflict resolution

隐身守侯 提交于 2019-11-27 14:46:09

Your assumption is right, the concrete method inherited from the superclass takes precedence over the default method from the interface:

JLS §8.4.8. Inheritance, Overriding, and Hiding

A class C inherits from its direct superclass and direct superinterfaces all abstract and default (§9.4) methods m for which all of the following are true:

  • No method declared in C has a signature that is a subsignature (§8.4.2) of the signature of m.
  • No concrete method inherited by C from its direct superclass has a signature that is a subsignature of the signature of m.

The second cited bullet applies here, there is a concrete method inherited from the direct superclass with an appropriate signature, so the default method is not inherited.

The documentation even clears any doubt with an additional remark:

Note that it is possible for an inherited concrete method to prevent the inheritance of an abstract or default method. (Later we will assert that the concrete method overrides the abstract or default method "from C".)

So it’s like SupCls.test() overrides Intf.test() when it comes to class Testing.

In other words, you are right, it’s a bug in Eclipse, but as long as it only affects the way the proposal is rendered, I’d consider it a minor bug. The inserted source will be the same, regardless of whether a D has been rendered in the proposal or not.

This certainly is a bug in eclipse but in the code completion proposals rather than in the compiler. Hovering over the call to test or Open Declaration take you to the SupCls method and running the code correctly prints "From SupCls" which proves this. Please file a bug against jdt ui for investigation

Looks like eclipse version matters!

In Eclipse Luna (4.4.1) the reference points to SupCls instead of Intf

Probably a bug in Eclipse Mars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!