Nice to see you, Scala

来源:互联网 发布:linux下zip 编辑:程序博客网 时间:2024/05/29 13:33

Nice to see you, Scala

mixin-based composition
Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.

方法和函数有一些区别:
函数是一个val
方法必须用def来定义
方法可以有多个参数,类似这样的

    def addThenMultiply(x: Int, y: Int)(multiplier: Int): Int = (x + y) * multiplier    println(addThenMultiply(1, 2)(3)) // 9class Greeter(prefix: String, suffix: String) {          def greet(name: String): Unit =          println(prefix + name + suffix)}    疑问:这里面的Unit是个什么数据类型呢

case class是不可变的按值比较的类

object 可以理解为单例

trait 只包含字段和方法,多个字段可以聚合
trait 可以被继承
被继承的时候可以重载里面的方法,关键字为override

Main函数

object Main{def main(args: Array[String]):Unit =    println("Hello, scala")}