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您也可以将该函数放入该类的伴随对象中。这可以保持清洁。 –