scala(一)
1.case class XX
表示建类时会自动创建一个伴生对象,伴生对象默认的apply方法
case class Person(val name: String, val age: Int) { } //相当于自动创建 object Person{ apply(val name: String, val age: Int){ return new Person(name,age) } }
2.implicit 隐式
对于函数可以定义隐式参数
def person(implicit name : String) = name implicit val p = "mobin" person
如果定义在方法前面则为隐式视图
implicit def doubleToInt(x: Double) = x.toInt
3.with
class A extends B with C with D with E 多继承
trait T1 { val a = 1 } trait T2 { val b = 2 } class SubClass extends T1 with T2 def func (x: T1 with T2) = { println("hello") }