美文网首页
2018-04-24 scala

2018-04-24 scala

作者: 江江江123 | 来源:发表于2018-06-04 16:24 被阅读0次

    类的主构造器:主构造器的变量会被执行,方法会被加载,调用的方法会被执行

    class Test1 {
     println("常量被加载了")
      def func(): Unit = {
        println("方法被调用了")
      }
    }
    object Test1{
      def main(args: Array[String]): Unit = {
        val test = new Test1
        test.func()
      }
    }
    

    辅助构造器:重载
    继承:extends
    实现:with

    隐式转换

    类增项,当类没有方法,但在另一个类中有,可以通过隐式转换调用

    class RichFile(file:File) {
      //拓展方法
     def read():String = {
       Source.fromFile(file.getPath).mkString
     }
    }
    object MyRichFile {
      //隐式转换
      implicit def fileToRichFile(file:File) = new RichFile(file)
    }
    object Test{
      def main(args: Array[String]): Unit = {
        //导入转换
        import MyRichFile.fileToRichFile
        val file = new File("C:\\Users\\54218\\Desktop\\test.txt")
        //打印文件内容
        println(file.read())
      }
    }
    

    柯里化

    将接受多个参数的方法函数变成一个一个接受的方法函数

    actor多线程

    AKKA RPC框架

    相关文章

      网友评论

          本文标题:2018-04-24 scala

          本文链接:https://www.haomeiwen.com/subject/kbudlftx.html