作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
据我所知,这两个函数是等效的:
def x(xx: X forSome { type X <: Int }): Unit = ()
def y[Y <: Int](yy: Y): Unit = ()
[]
),同时我有时会看到使用第一种形式(
forSome
)的文章(主要是旧的,讨论存在类型)。
最佳答案
它们确实非常相似,您并不孤单。我读过的关于存在类型的最好的文章确实给了你一个很好的解释 here (正如@DaunnC 提到的)。在Abstract Types中实际上还有第三种表达方式。 .
由于原因,我认为有些东西只是语法糖,而另一些则是语言演变的产物。 Scala 2.14计划解决一些冗余并简化语言。特别是:
Simplified and unified type syntax for all forms of information elision: existential types and partial type applications are both expressed with _, forSome syntax is eliminated.
关于scala - 类型和泛型 : difference between `[X <: Int]` and `{type X <: Int }` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30985612/
我是一名优秀的程序员,十分优秀!