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

1.1: Clarify that a class's implementation may come from interfaces

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8
    • specification

    Description

      A member of the public remarked that the JLS8 Introduction says "Classes support single implementation inheritance, in which the implementation of each class is derived from that of a single superclass." and that this is confusing when default methods in superinterfaces also help to derive the implementation of a class.

      It's not especially important to mention default methods per se, but it is important to suggest that the implementation of a class is derived from more than a superclass. (The Introduction has always ignored fields inherited from superinterfaces, presumably because they aren't seen as "implementation".) It's tricky without making a forward reference to superinterfaces when introducing classes. It's also undesirable to introduce concepts at too high a level, such as inheritance of "behavior" versus inheritance of "representation" or "state". Here's a suggestion:

      -----
      Chapter 8 describes classes. The members of classes are classes, interfaces, fields (variables), and methods. Class methods operate ... Instance methods are invoked ...

      Classes support single inheritance from other classes, in which each class has a single superclass. Each class inherits members from its superclass, and ultimately from the class Object. Variables of a class type can ...

      Chapter 9 describes interfaces. The members of interfaces are classes, interfaces, constant fields, and methods. Classes that are otherwise unrelated can implement the same interface. A variable of an interface type can contain a reference to any object that implements the interface. [Drop "Multiple interface inheritance is supported."]

      Classes and interfaces support multiple inheritance from interfaces. A class that implements one or more interfaces may inherit instance methods from both its superclass and its superinterfaces.
      -----

      Some related clarifications:

      - 9.1.3's opening paragraph only mentions methods, not instance methods, so accidentally catches static methods, contradicting 9.4.1 ("An interface does not inherit static methods from its superinterfaces.")

      - 9.4.1.3 compares a default method in an interface with a concrete method in a class, noting that neither is abstract, but we never say in 9.4 that a default method is an instance method. (Per 8.4.3.2, it is, because it lacks a static modifier.) Thus, the "direct extension" paragraph in 9's introduction fails to catch the fact that default methods are inherited.

      Attachments

        Activity

          People

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: