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

javac reports unnecessary unchecked warning

XMLWordPrintable

    • generic
    • solaris_8

      See
      http://forum.java.sun.com/thread.jsp?forum=316&thread=530883&tstart=0&trange=50

      Because arrays are covariant, there should be no unchecked warning in the
      following code. Removing the cast causes the warning to go away.

      ==========$ cat X.java
      class X {
          static <T, U extends T> T[] cast(U[] a) { return (T[]) a; }
      }
      ==========$ javac X.java -Xlint
      X.java:2: warning: [unchecked] unchecked cast
      found : U[]
      required: T[]
          static <T, U extends T> T[] cast(U[] a) { return (T[]) a; }
                                                                 ^
      1 warning
      ==========$

            ahe Peter Ahe
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: