Scala implicit 操作03
package scala_learn.demo12_Implicit
/**
* Created by liguohua on 2017/3/1.
*/
class O4_ImplicitDemo {
}
object O4_ImplicitDemo {
def main(args: Array[String]) {
implicit val name = "zhangsan"
implicit val age = 20
//test()//錯誤
//test//正確,
//test(name)//正確
//test(implicitly)//正確
test("xiaoqiang") //正確
//test2()//錯誤
//test2//正確
//test2(name,age)//正確
//test2(implicitly,implicitly)//正確
//test2(implicitly,67)//正確
//test2("huangzhong", 67) //正確
implicit val age2 = 25
//test2//錯誤
//test2(implicitly,implicitly)//錯誤
test2(implicitly,67)//正確
}
def test(implicit name: String): Unit = {
println(name)
}
def test2(implicit name: String, age: Int): Unit = {
println(name + "\t" + age)
}
}