最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

scala 3 - Define trait as supertype of existing built-in type - Stack Overflow

programmeradmin3浏览0评论

How do I say „Here's a trait Lookup with a get(key: String): Option[V] method which Map[String, V] already happens to implement”?

I tried

trait Lookup[V] {
  def get(key: String): Option[V]
}

but then I get

[error] 30 |  override def get(): Lookup[mine.Object] = Map(
[error]    |                                                          ^
[error]    |Found:    Map[String, Infrastructure]
[error]    |Required: dsd.ctms.afs.validation.Lookup[Infrastructure]

and I don't understand why. I can define trait Lookup[V] {def get(key: String): V} and then it's implemented by Map, but that is not the semantics I mean to capture.

发布评论

评论列表(0)

  1. 暂无评论