Duplicate arguments in 'setOf' and 'mapOf' functions
Reports duplicate constant elements in set factory functions and duplicate constant keys in map factory functions.
Duplicate entries in collection factory functions are often unintended and may indicate a bug or typo. In set factory functions, duplicate elements are ignored because sets can contain only unique elements. In map factory functions, entries with the same key overwrite earlier entries, and only the last value associated with the key is retained.
The inspection applies to the following map factory functions:
mapOf()mutableMapOf()hashMapOf()linkedMapOf()sortedMapOf()
Duplicate map keys are detected for entries created using the to operator.
The inspection applies to the following set factory functions:
setOf()mutableSetOf()hashSetOf()linkedSetOf()sortedSetOf()
The inspection reports arguments whose values can be evaluated as compile-time constants, including constant literals and references.
Examples:
The value 1 appears multiple times.
Both entries use the same key.
Example with const val:
Both arguments evaluate to the same constant value.
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
DuplicateArgumentsInSetOfAndMapOfFunctions- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection ID: DuplicateArgumentsInSetOfAndMapOfFunctions
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |