Package Com.leegh.implicits
Import Scala.io.Source
Import Java.io.File
/**
* @author Guohui Li
*/
Class Richerfile (Val file:file) {
def read = Source.fromfile (File.getpath). mkstring
}
Class File_implicits (path:string) extends File (path)
Associated objects
Object File_implicits {
Implicit def file2richfile (file:file) = new Richerfile (file)
}
The compiler performs a discovery file_implicits does not have a read method, and the context does not have an implicit import. See if the associated object of file_implicits is implicit conversion.
Implicit keyword, the parameter type matching, found that richerfile receive the same parameters, there is a read method
Object Implicits_internals {
def main (args:array[string]): Unit = {
println (New File_implicits ("E:\\leegh.txt"). Read)
}
}
Report:
This blog description:
1. Organize your ideas and improve yourself.
2. Be educated in Liaoliang teacher, what to gain, so recommend.
3. Blog focus on practice, superfluous words are not much to say, are doing technology.
4. Information from DT Big Data Dream Factory public account: Dt_spark.?
DT Big Data Dream Factory's public number is Dt_spark, every day will have big data actual combat video release, please continue to study.
Liaoliang DT Big Data dream factory Scala all videos, PPT and code in Baidu Cloud disk link:http://pan.baidu.com/share/home?uk=4013289088#category/type=0& Qq-pf-to=pcqq.group
Liaoliang "Scala Beginner's introductory classic video course" http://edu.51cto.com/lesson/id-66538.html
Liaoliang "Scala Advanced Classic Video Course" http://edu.51cto.com/lesson/id-67139.html
Implicit conversion in Scala Insider operating rules disclosure, best practices and their application in spark source parsing Scala learning notes-55