显然,对于 Foo.Bar,它像 Foo#Bar 一样工作,即if T is a type projection S#U, the parts of S as well as T itself
在隐式范围内(规范的 7.2,但请参阅隐式范围的常用资源,例如您已经在咨询)。(更新:这是这样一个资源。它并没有准确说明这种情况,以及一个真实的例子是否看起来像人为的。)
object Foo {
trait Bar
implicit def newBar = new Bar {
override def toString = "Implicit Bar"
}
}
class Foo2 {
trait Bar
def newBar = new Bar {
override def toString = "Implicit Bar"
}
}
object Foo2 {
val f = new Foo2
implicit val g = f.newBar
}
object Test extends App {
// expressing it this way makes it clearer
type B = Foo.type#Bar
//type B = Foo.Bar
type B = Foo2#Bar
def m(implicit b: B) = 1
println(implicitly[B])
println(m)
}