Scala type mismatch problem (expected Map, found scala.collection.mutable.HashMap)

淺唱寂寞╮ 提交于 2019-12-05 01:03:26

By default, the Map that is imported in a scala file is scala.collection.immutable.Map and not scala.collection.Map. And of course, in your case, HashMap is a mutable map, not an immutable one.

Thus if you want that Map refers to scala.collection.Map in your file, you have to import it explicitely:

import scala.collection.Map

The reason of this choice is that you will not manipulate an immutable and a mutable structure in the same way. Thus, scala infers by default that you will use immutable structure which are "most secure". If you don't want to do so, you must change it explicitly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!