首页 > 解决方案 > 如何在scala中实现自定义键映射?

问题描述

我得到了以下内容Mapscala并想在Map. 由于某种原因,它返回给定的错误。我可能必须为case objects? 如何Map使用自定义键对象实现 a?

sealed trait Status
case object Open extends Status
case object Processing extends Status
case object Completed extends Status

val map = Map(
    Open -> "open",
    Processing -> "processing",
    Meeting -> "meeting",
    MissingInformation -> "missing_information",
    Completed -> "completed"
  )
  
map(Open)
type mismatch;
found   : o.type (with underlying type example.Status)
required: Product with Serializable with example.Status

标签: scalacollections

解决方案


推荐阅读