Novotny
Novotny

Reputation: 322

Does Java's HashMap.get modify the map in any way?

Okay, so this is a silly question. I recently found dead code along the lines of:

Something a = hashMap.get("key");

IntelliJ Idea was complaining that a was never used, so I told it to remove it. At that point it yelled at me, that removing the entire line could have side effects, and it offered me to leave it as:

hashMap.get("key");

Now that got me thinking, what are the potential side effects of get?

Upvotes: 1

Views: 210

Answers (2)

CarManuel
CarManuel

Reputation: 325

I don't think there are any. The documentation does not mention any changes to map. I assume that it is yelling at you because you don't use a and it is an unnecessary variable. Hope this helps.

Upvotes: 0

gatti
gatti

Reputation: 1133

No, no side effects whatsoever!

Upvotes: 1

Related Questions