Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8304739

Elements.getAllMembers for an interface returns methods declared in java.lang.Object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • 21
    • core-libs
    • None

      javax.lang.model models interfaces in such a way that they are sometimes seen as having a superclass type, java.lang.Object. While it might be useful and pragmatic, the API should clearly indicate this divergence from JLS.

      For example, if Elements.getAllMembers is called for an interface, it will return a list that has ExecutableElements inherited from java.lang.Object: those are method members and they will have java.lang.Object as their enclosing element.


      Here are some relevant JLS excerpts.

      - 9.2. Interface Members:

      If an interface has no direct superinterface types, then the interface implicitly declares a public abstract member method m with signature s, return type r, and throws clause t corresponding to each public instance method m with signature s, return type r, and throws clause t declared in Object (§4.3.2), unless an abstract method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface.

      - 9.4.1.2. Requirements in Overriding:

      Second, interfaces do not inherit from Object, but rather implicitly declare many of the same methods as Object (§9.2). So, there is no common ancestor for the toString declared in Object and the toString declared in an interface. At best, if both were candidates for inheritance by a class, they would conflict. Working around this problem would require awkward commingling of the class and interface inheritance trees.

            darcy Joe Darcy
            prappo Pavel Rappo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: