How does java.util.Map's getOrDefault() work?

前端 未结 4 1113
刺人心
刺人心 2021-02-07 00:47

I noticed that if I do map.getOrDefault(\"key1\", new Object()), even if object is present for key1 in the map, new Object() is created. Though it is n

4条回答
  •  孤独总比滥情好
    2021-02-07 01:42

    This is not because of how the map is implemented, it is because of how Java works. The runtime interpreter has to create the object first (the new Empl part) before it can actually invoke the method (the getOrDefault part).

提交回复
热议问题