Scala

Scala

Made by DeepSource

Duplicate key in HashMap SC-W1019

Bug risk
Major

A duplicate key exists in the HashMap. This may lead to an unintentional behaviour as the key will always map to the last value provided to it and hence is always recommended that these keys be unique.

Bad practice

val freq = immutable.HashMap[Char, Int](('a', 1), ('b', 3), ('c', 4), ('a', 2))     // duplicate key 'a'

Recommended

All keys should be unique

val freq = immutable.HashMap[Char, Int](('a', 1), ('b', 3), ('c', 4))               // duplicate key 'a' removed