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

Project Coin: Simplified Varargs Method Invocation

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b100
    • CPU:
      unknown
    • OS:
      generic
    • Verification:
      Verified

      Description

      Quoting from project coin proposal at the following URL:

      http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000316.html

      "When a programmer tries to invoke a varargs (variable
      arity) method with a non-reifiable varargs type, the compiler currently
      generates an "unsafe operation" warning. This proposal moves the warning
      from the call site to the method declaration."

      BEFORE:

        static <T> List<T> asList(T... elements) { ... }

        static List<Callable<String>> stringFactories() {
          Callable<String> a, b, c;
          ...
          // Warning: "uses unchecked or unsafe operations"
          return asList(a, b, c);
        }

      AFTER (1):

        // Warning: "enables unsafe generic array creation"
        static <T> List<T> asList(T... elements) { ... }

        static List<Callable<String>> stringFactories() {
          Callable<String> a, b, c;
          ...
          // Warning: "uses unchecked or unsafe operations"
          return asList(a, b, c);
        }

      AFTER (2):

        @SuppressWarnings("generic-varargs")
        static <T> List<T> asList(T... elements) { ... } //no warning

        static List<Callable<String>> stringFactories() {
          Callable<String> a, b, c;
          ...
          // no warning
          return asList(a, b, c);
        }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                mcimadamore Maurizio Cimadamore
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: