package imp
object imp01 {
implicit def double2Int(d:Double):Int={
println("double2Int被调用了.....")
d.toInt
}
implicit def string2Int(d:String):Int={
println("string2Int.....")
1
}
def main(args: Array[String]): Unit = {
var i:Int = 1.1
i=2.1
i=3.1
i = "100"
var d:Double =1
}
}

package imp
object imp02 {
class KM(var value:Double) {
override def toString:String=s"${value}千米"
}
class M(var value:Double) {
override def toString:String=s"${value}米"
}
implicit def km2m(km:KM):M={
new M(1000 * km.value)
}
def main(args: Array[String]): Unit = {
val km1 =new KM(1)
val m1:M = km1
println(km1)
println(m1)
}
}

package imp
object imp03 {
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 (my.value * 0.14)
}
def main(args: Array[String]): Unit = {
val m1: RMB = new MY(100)
println(m1)
val my1:RMB = new RMB(1000)
println(my1)
}
}
