简体   繁体   English

Scala - 参数方法和forSome之间的区别

[英]Scala - Difference between parametric method and forSome

In Scala: 在斯卡拉:

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

vs.

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

They are not the same because in some cases only the latter one is working. 它们不一样,因为在某些情况下只有后者才有效。

forSome marks an existential type. forSome标志着一种存在主义类型。 Existential types may be used for client side type variance, which might be required for your use case. 存在类型可用于客户端类型差异,这可能是您的用例所必需的。 You can read more under this question. 您可以在此问题下阅读更多内容。

What is the forSome keyword in Scala for? Scala中的forSome关键字是什么?

or in the linked article 或在链接的文章中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM