Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala存在型怪异行为_Scala_Class_Inheritance_Types_Existential Type - Fatal编程技术网

Scala存在型怪异行为

Scala存在型怪异行为,scala,class,inheritance,types,existential-type,Scala,Class,Inheritance,Types,Existential Type,我的回复中有以下内容: scala> trait T[A] defined trait T scala> :kind T[A] forSome {type A} T[_]'s kind is A scala> :kind T[_] T[_]'s kind is A 现在当我这样做的时候: trait e[_] extends T[_] 我明白了 然而,以下工作: scala> trait e[_] extends T[Int] defined trait e

我的回复中有以下内容:

scala> trait T[A]
defined trait T

scala> :kind T[A] forSome {type A}
T[_]'s kind is A

scala> :kind T[_]
T[_]'s kind is A

现在当我这样做的时候:

trait e[_] extends T[_]
我明白了

然而,以下工作:

scala> trait e[_] extends T[Int]
defined trait e


为什么T[Int]和T[uz]是同一种类的,但它们的处理方式不同?

这不是关于种类,而是关于一个类型是否是包含特征的类类型

你可以写

type T <: U
仅适用于U类

子类型和继承/子类化是不同的

与特征T[a]对应的类型是每个类型a的类类型。因此T[Int]是类类型。当您编写扩展A[B]时,重要的是A是类类型,B可以是任意类型


某些{type A}的存在类型(如T[]aka T[A])不是类类型。你也可以把T[uz]看作是所有T[a]的超类型。事实上,T[u]是所有T[A]中最小的上界。

这不是关于种类,而是关于一个类型是否是包含特征的类类型

你可以写

type T <: U
仅适用于U类

子类型和继承/子类化是不同的

与特征T[a]对应的类型是每个类型a的类类型。因此T[Int]是类类型。当您编写扩展A[B]时,重要的是A是类类型,B可以是任意类型


某些{type A}的存在类型(如T[]aka T[A])不是类类型。你也可以把T[uz]看作是所有T[a]的超类型。事实上,T[u]是所有T[A]中最小的上界。

不一定要遵循这个问题,请展开一下好吗?@maatdeam存在类型不是类类型。@maatdeam,当你写trait e[u]时,它与trait e[X]是一样的。到了那里,只是确认T[Int]是类类型,但T[A]对于某些{type A}不是吗?是的,我从你上次的回复中得到了呼叫站点和定义站点的区别。因此,我正在测试一些东西。不确定是否要关注这个问题,请展开一下好吗?@Maatdeam存在类型不是类类型。@Maatdeam,当您编写trait e[1;]时,它与trait e[X]是相同的。到达那里,但只是确认T[Int]是类类型,但T[a]对于某些{type a}不是吗?是的,我从你上次的回复中得到了呼叫站点和定义站点的区别。因此,我在到处玩来测试东西。
type T <: U
trait T extends U