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

generics: extension of raw not treated as raw.

XMLWordPrintable

    • hopper
    • generic
    • solaris_7
    • Verified

      The following problem was reported in the context of the JSR14 prototype.
      Is this a problem with the specification or a problem with the compiler?


      frog$ cat -n JSR14Bug.java
           1 class Comparator<T> {}
           2 class Arrays {
           3 public static <T> void sort(T[] a, Comparator<T> c) {
           4 throw new Error();
           5 }
           6 }
           7
           8 class JSR14Bug {
           9 public static void main(String[] args) {
          10 Object[] oa;
          11 Arrays.sort(oa, new Comparator() {});
          12 }
          13 }
          14
      frog$ sh compile.sh
      JSR14Bug.java:11: sort(T[],Comparator<T>) in Arrays cannot be applied to (java.lang.Object[],<anonymous Comparator>)
              Arrays.sort(oa, new Comparator() {});
                    ^
      1 error
      frog$

      ===========================================

      Here is another, related problem:

      frog:~/workspaces/test/Generic1 $ cat -n T.java
           1 // from library
           2 interface Comparable<T> { }
           3 interface List<E> { }
           4 class Comparator<T> { }
           5
           6 class Collections {
           7 public static <T extends Object & Comparable<T>>
           8 int binarySearch(List<T> list, T key) {
           9 throw new Error();
          10 }
          11 public static <T>
          12 int binarySearch(List<T> list, T key, Comparator<T> c) {
          13 throw new Error();
          14 }
          15 }
          16
          17
          18 // user code below
          19 class Record implements Comparable { }
          20 class T {
          21 public static void main(String[] arg) {
          22 List records = null;
          23 Record x = null;
          24 int result = Collections.binarySearch(records, x);
          25 }
          26 }
      frog:~/workspaces/test/Generic1 $ newjavac -gj -warnunchecked T.java
      + /usr/local/java/jdk1.4/solsparc/bin/javac -J-Xbootclasspath/p:/net/frog/gafter/gjc-work/4445752.ws/build/bootstrap:/net/frog/gafter/gjc-work/4445752.ws/make/tools/javac/gjc.jar -bootclasspath /net/frog/gafter/gjc-work/4445752.ws/build/collections:/net/frog/gafter/gjc-work/4445752.ws/make/tools/javac/collect.jar:/usr/java1.4/jre/lib/rt.jar -gj -warnunchecked T.java
      T.java:24: cannot resolve symbol
      symbol : method binarySearch (List,Record)
      location: class Collections
              int result = Collections.binarySearch(records, x);
                                      ^
      1 error
      frog:~/workspaces/test/Generic1 $

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: