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

Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs

XMLWordPrintable

    • b12
    • unknown
    • generic
    • Verified

        This program:

        import java.util.ArrayList;
        import java.util.List;

         class X {
                @SafeVarargs
                static void m(List<String>... ls) {
                        Object[] o = ls; // 2 warning here
                        o[0] = new ArrayList<Integer>();
                        System.out.println(o);
                }
        }


        Generates two 'varargs' warnings when compiled with the -Xlint:varargs flag enabled.

        OUTPUT:

        Test.java:7: warning: [varargs] Varargs method could cause heap pollution from non-reifiable varargs parameter ls
                        Object[] o = ls; // 2 warning here
                                     ^
        Test.java:7: warning: [varargs] Varargs method could cause heap pollution from non-reifiable varargs parameter ls
                        Object[] o = ls; // 2 warning here
                                     ^
        2 warnings

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: