0
鑑於此真棒一塊完全親斯卡拉:斯卡拉 - 明確提及參數
trait SomethingCool {
def foo: Int => String
}
def makeSomethingCool(foo: Int => String = i => i.toString): SomethingCool = {
new SomethingCool {
override def foo = foo // method foo does nothing other than call itself recursively
}
}
在那裏我有,有一個默認的實現一個性狀的工廠方法,我怎麼能是指從內部參數名new SomethingCool { }
?它似乎被特質的功能名稱所掩蓋。
難道你不能只是調用參數別的東西? – marstran
我可以用某種「爲什麼沒有想到這個」或者「這不是對變量名稱範圍規則問題的回答」,但我不會。相反,我會說「謝謝你的建議,我會記住這一點。」 –
哦,我並沒有試圖粗魯或任何事情。對不起,如果你認爲。 – marstran