We could have used a val with a mutable type, like ListBuffer.
我们也可以使用val和一个可变的类型,比如ListBuffer。
Unlike strings, which are immutable, lists are a mutable type, i. e. it is possible to change their content.
不像字符串是不可变量,列表是可变类型,例如:它可以改变它本身某个元素的值。
Clearly, this approach is a pain but the solution is easy: Never use a mutable object type as a key in a HashMap.
很显然,这种方法很糟糕,但是解决方法也很简单:永远不要将可变对象类型用作hashmap中的键。
应用推荐