Skip to content

Files

Latest commit

 

History

History
37 lines (19 loc) · 729 Bytes

ExplicitCollectionElementAccessMethod.md

File metadata and controls

37 lines (19 loc) · 729 Bytes

Pattern: Missing use of indexed access operator []

Issue: -

Description

Prefer the usage of the indexed access operator [] for map or list element access or insert methods.

Example of incorrect code:

 val map = Map<String, String>()

 map.put("key", "value")

 val value = map.get("key")

Example of correct code:

 val map = Map<String, String>()

 map["key"] = "value"

 val value = map["key"]

Further Reading