Details
-
Bug
-
Resolution: Unresolved
-
P4
-
21
-
None
Description
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.
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.
Attachments
Issue Links
- relates to
-
JDK-8299917 Types.directSupertypes shouldn't include java.lang.Object for some interfaces
-
- Open
-
-
JDK-8302019 Clarify Elements.overrides
-
- Open
-
-
JDK-8303048 Elements.getAllMembers returns unexpected methods
-
- Open
-
-
JDK-8304806 Elements.getAllMembers returns interface methods where it should return class methods
-
- Open
-