1 package smart.iot 2 3 4 class ScalaStatic { 5 6 } 7 8 object statictest 9 { 10 def add(x:Int,y:Int):Int={x+y} 11 //以上的函数也可以写成下面的格式,省略掉花括号,返回值是scala自动推断出来的 12 //def add(x:Int,y:Int)=x+y 13 } 14 15 //ScalaStatic 的伴生类 16 object ScalaStatic 17 { 18 def main(args: Array[String]): Unit = { 19 20 21 var data=statictest.add(1, 6) 22 println(data); 23 } 24 }
原文:http://www.cnblogs.com/IChing/p/7093786.html