Is a Path Dependent Type a subtype?

前端 未结 3 809
花落未央
花落未央 2021-01-06 07:18
trait A {
  trait B {
    def foo: A.this.B = new B{}
    def bar: A#B      = foo 
    def baz: A.this.B = bar // type mismatch; found : A#B required: A.this.B 
  }
         


        
3条回答
  •  逝去的感伤
    2021-01-06 08:07

    In short: Yes it is

    If you want, you can consider A#B to have an abstract reference to the containing A (and therefore not directly constructable, as for any abstract type), this reference being made concrete in the path-dependent subclasses.

提交回复
热议问题