案例类可以作为函数传递,我怎样才能让常规类以同样的方式作为函数传递?
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)
}