加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

泛型 – Scala中的MultiMap

发布时间:2020-12-16 09:35:49 所属栏目:安全 来源:网络整理
导读:我正在尝试将MultiMap trait与HashMap混合,如下所示: val children:MultiMap[Integer,TreeNode] = new HashMap[Integer,Set[TreeNode]] with MultiMap[Integer,TreeNode] MultiMap trait的定义是: trait MultiMap[A,B] extends Map[A,Set[B]] 意思是A A类
我正在尝试将MultiMap trait与HashMap混合,如下所示:

val children:MultiMap[Integer,TreeNode] = 
    new HashMap[Integer,Set[TreeNode]] with MultiMap[Integer,TreeNode]

MultiMap trait的定义是:

trait MultiMap[A,B] extends Map[A,Set[B]]

意思是A& A类型的MultiMap B是A& A类的地图设置[B],好像在我看来。但编译器抱怨:

C:...TestTreeDataModel.scala:87: error: illegal inheritance;   template $anon inherits different type instances of trait Map:   scala.collection.mutable.Map[Integer,scala.collection.mutable.Set[package.TreeNode]] and scala.collection.mutable.Map[Integer,Set[package.TreeNode]]  
    new HashMap[Integer,TreeNode]  
    ^ one error found

仿制药似乎再次绊倒了我。

解决方法

我不得不导入scala.collection.mutable.Set。似乎编译器认为Set in HashMap [Integer,Set [TreeNode]]是scala.collection.Set。 MultiMap中的Set def是scala.collection.mutable.Set。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读