Call to 'Arrays.asList()' with too few arguments
Reports calls to Arrays.asList() with at most one argument.
Such calls could be replaced with Collections.singletonList(), Collections.emptyList(), or List.of() on JDK 9 and later, which will save some memory.
In particular, Collections.emptyList() and List.of() with no arguments always return a shared instance, while Arrays.asList() with no arguments creates a new object every time it's called.
Note: the lists returned by Collections.singletonList() and List.of() are immutable, while the list returned Arrays.asList() allows calling the set() method. This may break the code in rare cases.
Example:
After the quick-fix is applied:
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.
ArraysAsListWithZeroOrOneArgument- 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.
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: |