Mutable values in an object
问题 In Scala, if I'm planning on having a mutable attribute (e.g. a bag of numbers) of an object, when is it appropriate to Create a var and use an immutable data structure? Create a val and use a mutable data structure? I'm going to throw a guess out that you'd want to use #2 for threaded applications? Are some of the collections thread-safe? How about in general? (Or does it not really matter?) 回答1: Between your choices 1 and 2, it doesn't matter - mutable is mutable, and if you read or modify