这是我的userRepository特征
import scala.collection.mutable.Map
trait userRepository {
def addUser(id: String, user:USER):Map[String,USER]
def removeUser(id: String):Map[String,USER]
def getUser(id: String):Map[String,USER]
}
这是我的userRepositoryImpl类
import scala.collection.mutable.Map
class userRepositoryImpl extends userRepository {
val userMap = Map.empty[String,USER]
override def addUser(id: String, user: USER): Map[String,USER] = {
userMap.put(id, user)
}
override def removeUser(id: String): Map[String,USER] = {
userMap.remove(id)
}
override def getUser(id: String): Map[String,USER] = {
userMap.find(_._2.id == id)
}
}
这是我的USER类
case class USER(id: String, firstName: String, lastName: String, email: String, address: String, gender: String)
Earro
type mismatch;
found : Option[USER]
required: scala.collection.mutable.Map[String,USER]
userMap.put(id, user)
为什么我会出现这个错误?有朋友能解释一下原因吗?
谢谢,它通过返回";userMap";。
例如
override def removeUser(id: String): Map[String, USER] = {
userMap.remove(id)
userMap
}
这是不匹配错误