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

5.4: field resolution order for superinterfaces

    Details

    • Subcomponent:
      vm

      Description

      Step (2) of JVMS 10 5.4.3.2 says:

      > Otherwise, field lookup is applied recursively to the direct superinterfaces of the specified class or interface C.

      If multiple superinterfaces declare a field with the name and descriptor specified by the field reference, what happens?

      The implementation currently chooses the field from the first such superinterface, in declaration order. If that behaviour is guaranteed, could it be made explicit in the spec?

      In JVMS 10 5.4.3.4 step 5 and JVMS 10 5.4.3.3 step 3, the spec says that a choice is made "arbitrarily" for method resolution if multiple superinterfaces declare a method with the matching name and descriptor. If behaviour for fields is also up to the implementation, could similar language be added to 5.4.3.2?

      Demo:

      === A_one.java
      interface A {
      }
      === A_two.java
      interface A {
        Boolean x = true;
      }
      === T.java
      interface B {
        Boolean x = false;
      }

      class One implements A, B {
        public static void main(String[] args) {
          System.err.println(One.x);
        }
      }

      class Two implements B, A {
        public static void main(String[] args) {
          System.err.println(Two.x);
        }
      }
      ===

      $ javac T.java A_one.java
      $ javac A_two.java

      # getstatic One.x resolves to A.x
      $ java One
      true

      # getstatic Two.x resolves to B.x
      $ java Two
      false

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                cushon Liam Miller-Cushon
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: