Scala基础3

    xiaoxiao2021-03-25  129

    1. scala的work sheet,每次保存时,可以直接列出结果,可以进行简单测试

    例如:

    object hello1 {

      println("Welcome to the Scala worksheet")       //> Welcome to the Scala worksheet   println("hello")                                //> hello      def  abs(i:Int)= if (i>0) i else -i             //> abs: (i: Int)Int      abs(2)                                          //> res0: Int = 2   abs(-2)                                         //> res1: Int = 2

    }

    2. scala不要求类名和文件名一致

    3. scala中没有static,scala中的object 就是一个实例,同时类似于static,可以直接调用其中的方法,与单例类似,当不希望创建多个时,可以用object。

    转载请注明原文地址: https://ju.6miu.com/read-7059.html

    最新回复(0)