0
是否可以爲類的隱式參數表示默認值?上述隱式參數的默認行爲
class I[T](val t: T)
class A(i: I[Int])(implicit f: I[Int] => Int) {
implicit object key extends(I[Int] => Int) {
def apply(i: I[Int])= i.t
}
def this() = this(new I(0))(key)
}
的代碼提供「錯誤:未找到:值鍵」
很明顯,使用此方法,但實際的情況是更comlicated,我有多個構造函數,是可以減少代碼的副本。 – kokorins
@kokorins您也可以將該函數放入該類的伴隨對象中。這可以保持清潔。 –