Public Mutable Property (ARCH8186)
Ce contenu n’est pas encore disponible dans votre langue.
Key kotlin.quality.public-mutable-field · Severity warning · Category quality
Flags public var properties on classes - state anyone can change from anywhere.
Incorrect
Section titled “Incorrect”class Cart { var items = mutableListOf<Item>() }Correct
Section titled “Correct”class Cart { private val _items = mutableListOf<Item>() val items: List<Item> get() = _items}Use private set or expose a read-only view.