• Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • None
    • core-libs

      The Map.ofEntries() method is currently

        static <K, V> Map<K, V> ofEntries(Entry<K, V>... entries)

      It should probably be changed to

        static <K, V> Map<K, V> ofEntries(Entry<? extends K, ? extends V>... entries)

      For most cases it won't make a difference, but for (probably fairly obscure) cases where you already have Map.Entry instances containing subtypes of the desired Map key/value types, it will be helpful. For example:

          Map.Entry<Integer, Integer> e1 = entry(1, 2);
          Map.Entry<Double, Double> e2 = entry(3.0, 4.0);
          Map<Number, Number> map = Map.ofEntries(e1, e2);

      The last line gives an error with the non-wildcard signature. This error doesn't occur if wildcards are added.

      It doesn't seem to be a problem if the generic types for the Map.Entry instances are inferred. For example, the following works OK:

          Map<Number, Number> map2 = Map.ofEntries(entry(1, 2.0), entry(3.0f, 4L));

            smarks Stuart Marks
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: