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

Elements.getAllMembers returns method declared in java.lang.Object



    • Bug
    • Resolution: Unresolved
    • P4
    • 23
    • 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.

      - 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.


        Issue Links



              darcy Joe Darcy
              prappo Pavel Rappo
              0 Vote for this issue
              1 Start watching this issue