2
我有以下代碼:isInstanceOf與路徑依賴型工作
class Outer {
class Inner
}
val outer1 = new Outer
val outer2 = new Outer
val a1 = new outer1.Inner
val a2 = new outer2.Inner
val a2: outer2.Inner = a1
println(a1.isInstanceOf[outer2.Inner])
我知道val a2: outer2.Inner = a1
已編譯因爲路徑依賴型的錯誤,但我不明白爲什麼println(a1.isInstanceOf[outer2.Inner])
將打印true
這是因爲a1和a2都指向Outer.Inner類的相同位置。 –