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_Generics_Typing - Fatal编程技术网

Scala 当涉及自类型时,为什么类型成员边界停止工作

Scala 当涉及自类型时,为什么类型成员边界停止工作,scala,generics,typing,Scala,Generics,Typing,假设我用自我类型定义了一些特征。特质和自我类型都有一个抽象类型的成员。trait中的self类型应该覆盖self类型中的抽象类型成员 trait Foo{ type My def make:Seq[My] } trait Component { type My } trait Bar extends Foo { this:Component => override type My <: StuffDoer def len = make.map(_.doStu

假设我用自我类型定义了一些特征。特质和自我类型都有一个抽象类型的成员。trait中的self类型应该覆盖self类型中的抽象类型成员

trait Foo{
  type My
  def make:Seq[My]
}

trait Component {
  type My
}

trait Bar extends Foo { this:Component =>
  override type My <: StuffDoer

  def len = make.map(_.doStuff)

  class StuffDoer(str:String) {
    def doStuff = "blah"
  }
}
似乎
My
Bar
的内部不一定是
StuffDoer
类型,但为什么?
My
Bar
内部的确切界限是什么?
组件是否覆盖其类型边界


更奇怪的是,当我更改
覆盖类型My时,如果类
StuffDoer
有方法
doStuff
,那么所有子类都有方法,但不是所有子类型都有方法。例如
Nothing
Null
StuffDoer
的子类型,但您不能对
Nothing
Null
类型的变量
x
调用
doStuff

Error:(20, 24) value doStuff is not a member of Bar.this.My
    def len = make.map(_.doStuff)
override type My = StuffDoer