Skip to content

Constructing a map from java.util.Map #18

@skogsbaer

Description

@skogsbaer

The following does not work:

java.util.Map<String, Integer> javaMap = new java.util.HashMap<String, Integer>();
Map<String, Integer> immutableMap = Maps.copyOf(javaMap.entrySet());

Compile error:

build/plugins/java/Dexx.java:20: error: no suitable method found for copyOf(java.util.Map<String,Integer>)
Map<String, Integer> immutableMap = Maps.copyOf(javaMap);
                                        ^
    method Maps.<K#1,V#1>copyOf(Iterable<Pair<K#1,V#1>>) is not applicable
      (cannot infer type-variable(s) K#1,V#1
        (argument mismatch; java.util.Map<String,Integer> cannot be converted to Iterable<Pair<K#1,V#1>>))
    method Maps.<K#2,V#2>copyOf(Iterator<Pair<K#2,V#2>>) is not applicable
      (cannot infer type-variable(s) K#2,V#2
        (argument mismatch; java.util.Map<String,Integer> cannot be converted to Iterator<Pair<K#2,V#2>>))
    method Maps.<K#3,V#3>copyOf(Pair<K#3,V#3>[]) is not applicable
      (cannot infer type-variable(s) K#3,V#3
        (argument mismatch; java.util.Map<String,Integer> cannot be converted to Pair<K#3,V#3>[]))
  where K#1,V#1,K#2,V#2,K#3,V#3 are type-variables:
    K#1 extends Object declared in method <K#1,V#1>copyOf(Iterable<Pair<K#1,V#1>>)
    V#1 extends Object declared in method <K#1,V#1>copyOf(Iterable<Pair<K#1,V#1>>)
    K#2 extends Object declared in method <K#2,V#2>copyOf(Iterator<Pair<K#2,V#2>>)
    V#2 extends Object declared in method <K#2,V#2>copyOf(Iterator<Pair<K#2,V#2>>)
    K#3 extends Object declared in method <K#3,V#3>copyOf(Pair<K#3,V#3>[])
    V#3 extends Object declared in method <K#3,V#3>copyOf(Pair<K#3,V#3>[])

It would be nice to have a method in Maps that allows to construct a Map from a java.util.Map

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions