【发布时间】:2016-06-03 05:48:42
【问题描述】:
以下作品:
class Outter {
type Inner = Either[Int,String]
type L = Left[Int,String]
type R = Right[Int,String]
def f(x: Inner) = 1
}
val o = new Outter
o.f(new o.L(1))
o.f(new o.R("name"))
但这仅仅是因为Inner 的所有子类型都有一个明确的type 成员。是否可以从路径相关类型的子类型构造一个值,而 不需要在 Outter 中明确提及它们?喜欢:
class Outter {
type Inner = Either[Int,String]
def f(x: Inner) = 1
}
val o = new Outter
o.f(new o.?!?(1)) // How do I express "that particular Left[Int,String] which is the sub-type of o.Inner
o.f(new o.?!?("name")) // same as above here, but for Right
【问题讨论】: