继承自mutable.Map会导致问题

时间:2012-02-20 07:37:40

标签: scala

我正在创建一个新类,我继承自mutable.Map

class Env extends mutable.Map[String, Any] {
  var outer = new mutable.Map[String, Any]
  def get(name: String): Any = if (super.get(name).isEmpty) outer.get(name) else super.get(name)
}

我得到的错误是:

Test.scala:6: error: method get in trait MapLike is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'

为什么?

1 个答案:

答案 0 :(得分:3)

mutable.Map trait ,其get方法未实现(即抽象)。

你应该扩展mutable.HashMap。但是,请记住,映射get方法会返回一个Option而不是直接返回存储的值。