大小寫類可以作爲函數傳遞,我怎樣才能讓一個普通類以同樣的方式作爲函數傳遞?爲什麼大小寫類可以作爲函數傳遞
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)
}