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

Improve wildcards diagnostics: "capture of ?"

XMLWordPrintable

    • b71
    • generic
    • generic, solaris_8
    • Verified

      The error message uses 'incompatible types' with the notation '=?', which I"m nost sure is all that clear. Will users be familiar with '=' in generic notation enough to diagnose? I wish I had a better suggestion, maybe something about writing to a read only class.
       
      class test
      {
        class A {}
        class B extends A {}
        class List<T> { List<T> next; T t; }

        <A> List<? extends A> bad_reverse(List<? extends A> xs)
        {
          List<? extends A> tmp1 = xs, tmp2 = xs.next;
          tmp2.next = tmp1; // <<fail>> attempt to write to readonly class
          return tmp1;
        }
      }

      ----------error message-----------
      test.java:21: incompatible types
      found : test.List<? extends A>
      required: test.List<=? extends A>
          tmp2.next = tmp1; // <<fail>>
                      ^

            ahe Peter Ahe
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: