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

interfaces extend Object?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.0
    • specification
    • None
    • generic
    • solaris_8

      To: ###@###.###, ###@###.###
      CC: ###@###.###
      Subject: interfaces extend Object?

      javac's implementation of interfaces doesn't quite follow the JLS
      description of how interfaces work, and the result isn't quite
      seamless. Specifically, javac acts internally as if an interface
      (that doesn't extend another interface) inherits from Object. But the
      JLS 9.2 says that the interface "implicitly defines" those public
      methods from Object, and doesn't extend Object. Here are the
      consequences of javac's implementation strategy:

      (1) Although the JLS says such methods are "implicitly" defined by the
          interface, they don't appear in the class file. That's a bug;
          they are required to appear in the class file as a consequence of
          9.2 and 13.1. Note that fixing this will affect the APIs visible
          through reflection of most interfaces. 4644624

      (2) The qualifying type for Object methods accessed from an interface
          should be the interface according to the JLS, but javac outputs
          Object as the qualifier. I now disagree with the comments on
          bugids 4285499 and 4398789 that the qualifying type should be
          Object due to JLS 13.1; the logic there is incorrect because the
          method is not "declared in Object", but rather is "implicitly"
          declared in the interface; the corresponding method from Object
          is separate and has no relationship to the one in the interface.

      (3) javac fails to allow some definitions that it should when those
          definitions are incompatible with protected definitions inherited
          from Object. 4479264

      (4) Within a class nested within the interface, the protected members
          of Object are visible but shouldn't be. 4526026

      The last two points are strictly compiler issues; I can implement a
      constraint in the compiler that protected members are never inherited
      into an interface to make those problems go away. However, (1) and
      (2) will be serious compatibility issues if javac ever actually
      implements what the spec requires. I am uncomfortable leaving things
      in their current state, so I'd like some definitive decision as to
      whether javac or the specification should be changed.

      -Neal

            abuckley Alex Buckley
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: