【问题标题】:Scala - Difference between parametric method and forSomeScala - 参数方法和 forSome 之间的区别
【发布时间】:2017-03-02 22:06:22
【问题描述】:

在 Scala 中:

def rules[T]: Array[Rule[T]]= { ... }

对比

def rules: Array[Rule[T]] forSome {type T} = { ... }

它们不一样,因为在某些情况下,只有后者起作用。

【问题讨论】:

  • 不是答案,而是最重要的区别:您想要后一个版本的情况几乎为零。

标签: scala generics types


【解决方案1】:

forSome 标记存在类型。现有类型可用于客户端类型差异,这可能是您的用例所必需的。您可以在此问题下阅读更多内容。

What is the forSome keyword in Scala for?

或在链接的文章中

http://scalada.blogspot.de/2008/01/existential-types.html

【讨论】:

  • 但是我想知道这两个成语有什么区别
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-23
  • 2013-06-16
  • 1970-01-01
  • 2013-01-04
  • 2013-04-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多