scala语法
函数
(x: Int) => x + 1
方法1
def add(x: Int, y: Int): Int = x + y
运行
println(add(1, 2))
#3
方法2
def addThenMultiply(x: Int, y: Int)(multiplier: Int): Int = (x + y) * multiplier
运行
println(addThenMultiply(1, 2)
//3
方法3
def name: String = System.getProperty("user.name")
运行
println("Hello, " + name + "!")
//
方法
def getSquareString(input: Double): String = { val square = input * input square.toString }
运行
println(getSquareString(2.5))
类
class Greeter(prefix: String, suffix: String) { def greet(name: String): Unit = println(prefix + name + suffix) }
运行
val greeter = new Greeter("Hello, ", "!") greeter.greet("Scala developer")
========================================================