Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 492

Answer by Federico klez Culloca for no instance(s) of type variable(s) K, V exist so that Map conforms to HashMap

$
0
0

Map.of doesn't return a HashMap, it returns an unmodifiable map (what type that is exactly is implementation-dependent and not important), so you can't assign it to a HashMap.

You can work around that by using the HashMap's constructor that accepts (and makes a copy of) another map as an argument.

HashMap<String, String> hashMap = new HashMap<>(Map.of("name", "Murife"));

Viewing all articles
Browse latest Browse all 492

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>