类型和泛型:`[X <: Int]` 和`{type X <: Int }` 之间的区别

Types and generics: difference between `[X <: Int]` and `{type X <: Int }`

据我所知,这两个函数是等价的:

def x(xx: X forSome { type X <: Int }): Unit = ()

def y[Y <: Int](yy: Y): Unit = ()

根据我的观察,现在人们大多使用第二种形式(使用[]),同时我有时会看到使用第一种形式(forSome).

有2个符号的原因是什么?有没有 pros\cons 或你 can\can 不使用其中之一的事情?

它们确实非常相似,而且您并不孤单。我读过的关于存在类型的最好的文章给了你一个很好的解释确实是 here (as @DaunnC mentions) . There is actually also a third way to express the same in 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.