से आने वाले पथ-निर्भर प्रकार का खुलासा करना मैं स्केल को एक सिंगलटन प्रकार से आने वाले पथ-निर्भर प्रकार के लिए सही प्रकार खोजने का प्रयास कर रहा हूं।एक सिंगलटन प्रकार
सबसे पहले, यहाँ उदाहरण के लिए प्रकार कंटेनर है, और एक उदाहरण:
trait Container {
type X
def get(): X
}
val container = new Container {
type X = String
def get(): X = ""
}
मैं इस पहले ही प्रयास में स्ट्रिंग देख सकते हैं (ताकि मैं पहले से ही काम कर रहे परिदृश्य है):
class WithTypeParam[C <: Container](val c: C) {
def getFromContainer(): c.X = c.get()
}
val withTypeParam = new WithTypeParam[container.type](container)
// good, I see the String!
val foo: String = withTypeParam.getFromContainer()
लेकिन जब कोई प्रकार पैरामीटर नहीं है, तो यह अब और काम नहीं करता है।
class NoTypeParam(val c: Container) {
def getFromContainer(): c.X = c.get()
}
val noTypeParam = new NoTypeParam(container)
// this does *not* compile
val bar: String = noTypeParam.getFromContainer()
क्या किसी को पता है कि टाइप पैरामीटर की आवश्यकता क्यों है?