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"));