import scala.io.Source
import java.io.File
//增强类
class RichFile (val file:File) {
def read = Source.fromFile(file.getPath()).mkString
}
object Context{
//implicit 声明并定义隐士函数
implicit def file2RichFile(file:File) = new RichFile(file)
}
object Hello_Implicit{
def main(args:Array[String]){
、 //引入隐士转换,在程序运行的最后会查看当前作用域是否有隐士转换,如果有则进行转换
import Context.file2RichFile
println(new File("").read)
}
}
转载于:https://my.oschina.net/u/1169079/blog/614376