package imp
object imp01 {
implicit def double2Int(d:Double):Int = {
println("double2Int被调用了...")
d.toInt
}
def main(args: Array[String]): Unit = {
var i:Int = 1.1
var d:Double = 1
}
}
object imp02 {
class MY(var value:Double) {
override def toString:String = s"${value}美元"
}
class RMB(var value:Double) {
override def toString: String = s"${value}人民币"
}
implicit def my2rmb(my:MY):RMB = {
new RMB(my.value * 6.9)
}
implicit def rmb2my(my:MY):MY = {
new MY(rmb.value * 0.14)
}
def main(args: Array[String]): Unit = {
val m1:RMB = new MY(100)
println(m1)
val my1:MY = new RMB(1000)
println(my1)
}
}