val-mutable versus var-immutable in Scala

后端 未结 5 2321
慢半拍i
慢半拍i 2020-11-27 10:40

Are there any guidelines in Scala on when to use val with a mutable collection versus using var with an immutable collection? Or should you really aim for val with an immuta

5条回答
  •  Happy的楠姐
    2020-11-27 11:24

    I think the examples in this blog post will shed more light, as the question of which combo to use becomes even more important in concurrency scenarios: importance of immutability for concurrency. And while we're at it, note the preferred use of synchronised vs @volatile vs something like AtomicReference: three tools

提交回复
热议问题