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

10.2: Clarify formulation of an array type

    XMLWordPrintable

Details

    Description

      (This bug is in response to two threads on type-annotations-spec-observers in March/April 2014: "ordering of annotated array brackets" and "annotated type of array-typed varargs parameter".)

      Most kinds of declaration can employ an array type denoted with post-identifier brackets. Where this happens, JLS8 formulates the array type of the declared entity in a similar fashion for each kind of declaration:

      // Variables

      - 8.3: The declared type of a field is denoted by the UnannType that appears in the field declaration, followed by any bracket pairs that follow the Identifier in the declarator.
      - 9.3: The declared type of a field is denoted by the UnannType that appears in the field declaration, followed by any bracket pairs that follow the Identifier in the declarator.

      - 14.4.1: The declared type of a local variable is denoted by the UnannType that appears in the local variable declaration, followed by any bracket pairs that follow the Identifier in the declarator.
      - 14.14.2: If the UnannType of the local variable in the header of the enhanced for statement is a reference type, then TargetType is the UnannType; otherwise, TargetType is the upper bound of the capture conversion (§5.1.10) of the type argument of I, or Object if I is raw.
      - 14.14.2: TargetType is the type of the local variable denoted by UnannType in the header of the enhanced for statement, followed by any bracket pairs that follow the Identifier (§10.2).

      - 8.4.1: The declared type of a formal parameter is denoted by the UnannType that appears in its parameter specifier, followed by any bracket pairs that follow the Identifier in the declarator, except for a variable arity parameter, whose declared type is an array type whose component type is the UnannType that appears in its parameter specifier.
      - 15.27.1: The declared type of a formal parameter is denoted by the UnannType that appears in its parameter specifier, followed by any bracket pairs that follow the Identifier in the declarator, except for a variable arity parameter, whose declared type is an array type whose component type is the UnannType that appears in its parameter specifier.

      // Methods

      - 8.4: The declaration of a method that returns an array is allowed to place some or all of the bracket pairs that denote the array type after the formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code.
      - 9.6.1: The declaration of a method that returns an array is allowed to place the bracket pair that denotes the array type after the empty formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code.

      - 8.4.5: The result of a method declaration either declares the type of value that the method returns (the return type), ... [The return type is not defined per se.]

      It would be best to centralize the definitions, such as:

      - 8.3: The declared type of a field is denoted by UnannType if no bracket pairs appear in UnannType and VariableDeclaratorId, and is specified by 10.2 otherwise.
      - 9.3: The declared type of a field is denoted by UnannType if no bracket pairs appear in UnannType and VariableDeclaratorId, and is specified by 10.2 otherwise.

      - 14.4.1: The declared type of a local variable is denoted by UnannType if no bracket pairs appear in UnannType and VariableDeclaratorId, and is specified by 10.2 otherwise.
      - 14.14.2: The declared type of the local variable in the header of the enhanced for statement is denoted by UnannType if no bracket pairs appear in UnannType and VariableDeclaratorId, and is specified in 10.2 otherwise. [Then in the case analysis of Expression's type, replace references to UnannType with "the declared type of the local variable".]

      - 8.4.1, 15.27.1: The declared type of a formal parameter depends on whether it is a variable arity parameter: 1) If the formal parameter is not a variable arity parameter, then the declared type is denoted by UnannType if no bracket pairs appear in UnannType and VariableDeclaratorId, and specified by 10.2 otherwise. 2) If the formal parameter is a variable arity parameter, then the declared type is specified by 10.2. (Note that mixed array notation is not permitted for variable arity parameters.)

      - 8.4.5: The return type of a method is denoted by Result if no bracket pairs appear after the formal parameter list, and is specified by 10.2 otherwise.

      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: