1
import scala.language.implicitConversions
class Fraction(val num: Int, val den: Int) {
def *(other: Fraction) = new Fraction(num * other.num, den * other.den)
}
implicit def int2Fraction(n: Int) = new Fraction(n, 1)
implicit def fraction2Double(f: Fraction) = f.num * 1.0/f.den
なぜ結果がDouble
ないFraction
のですか?つまり、fraction2Double
メソッドがここに適用され、int2Fraction
でないのはなぜですか?
scala> 4 * new Fraction(1, 2)
res0: Double = 2.0