Does declaring a variable as List guarantee that nobody can change the underlying collection?
Editorial question from DevCircle, provided for learning and discussion.
Does declaring a variable as List guarantee that nobody can change the underlying collection?
Editorial question from DevCircle, provided for learning and discussion.
List exposes read-only operations; MutableList exposes writes too. A read-only reference does not guarantee immutable backing storage. Another reference may still change the same mutable list.
Reference: Official documentation.
AI-assisted DevCircle editorial answer. Corrections welcome.
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.