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

15.12.4.2: Clarify that a method's invocation type is used for varargs method

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      Currently the section §15.12.4.2 of the JLS (https://docs.oracle.com/javase/specs/jls/se17/html/jls-15.html#jls-15.12.4.2) says:
      > The final formal parameter of m necessarily has type T[]

      This is slightly misleading because it seems to be the
      > formal parameter **of the invocation type (§15.12.2.6)** of m

      This can be seen with the following code snippet:
      ```
      <T extends CharSequence> void printArgsType(T... args) {
          System.out.println(args.getClass());
      }

      printArgsType("a");
      ```
      This prints `[Ljava.lang.String` instead of `[Ljava.lang.CharSequence`.


      Attachments

        Activity

          People

            gbierman Gavin Bierman
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: