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

Remove restrictions from @SafeVarargs

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      Currently there exist restrictions on which methods @SafeVarargs can be used, namely final, static or private methods. This makes usage of varargs generic parameters for public non-static interface methods extremely annoying:
      - The compiler issues a warning for the method declaration itself
      - The compiler issues a warning for every usage of the method

      Therefore it would be good to remove these @SafeVarargs restrictions and allow placing it on any varargs method. To provide additional safety, it could be enforced that every method overriding a method annotated with @SafeVarargs has to be annotated with @SafeVarargs itself as well (this is possible because the retention of @SafeVarags is RUNTIME).

      The annotation already acts as a "I know what I am doing" indicator, but even with the current implementation it can be used incorrectly (Javadoc of SafeVarargs has an example for this). Therefore there is (most likely) no big difference in allowing its usage on all methods.


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: