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

new rewrite rules versus wildcards in ConcurrentHashMap

XMLWordPrintable

    • generic, x86
    • solaris_8, windows_xp

      The new rewrite rules invalidate the following snippet of code from ConcurrentHashMap.java.

          public void putAll(Map<? extends K, ? extends V> t) {
              Iterator<Map.Entry<? extends K, ? extends V>> it = t.entrySet().iterator();
              while (it.hasNext()) {
                  Entry<? extends K, ? extends V> e = it.next();
                  put(e.getKey(), e.getValue());
              }
          }

      ==========$ cat T.java
      import java.util.*;

      class Main<K, V> {
          public void main(Map<? extends K, ? extends V> t) {
              Iterator<Map.Entry<? extends K, ? extends V>> it = t.entrySet().iterator();
          }
      }
      ==========$ newjavac T.java
      + exec /usr/java1.5/bin/javac -J-esa -source 1.5 -target 1.4 T.java
      T.java:5: incompatible types
      found : ? extends java.util.Iterator<? extends java.util.Map.Entry<? extends K,? extends V>>
      required: java.util.Iterator<java.util.Map.Entry<? extends K,? extends V>>
              Iterator<Map.Entry<? extends K, ? extends V>> it = t.entrySet().iterator();
                                                                                      ^
      1 error
      ==========$

            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: