Is a Path Dependent Type a subtype?

前端 未结 3 841
花落未央
花落未央 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:10

    Yes, it's a path dependent type. Yes, all instances of B are members of A#B. Note that you can't directly construct an instance of A#B, all instances of B must have a reference to the outer A instance

提交回复
热议问题