大小写类可以作为函数传递,我怎样才能让一个普通类以同样的方式作为函数传递?为什么大小写类可以作为函数传递
case class Fraction(val num: Int, val den: Int)
object Run extends App {
def doFraction(in: (Int, Int) => Fraction) {}
doFraction(Fraction)
}
上面的代码工作,我如何修改下面的代码以获得相同的效果?
class Fraction(val num: Int, val den: Int) {
/* what can I put here or in companion object to make this compile? */
}
object Fraction {
/* ... */
}
object Run extends App {
def doFraction(in: (Int, Int) => Fraction) {}
doFraction(Fraction)
}