Scala链式编程内幕

时间:2024-07-28 12:37:02
 package big.data.analyse.scala

 /**
* 链式编程原理
* Created by zhen on 2018/12/16.
*/
class Computer{def code = this}
class PC extends Computer{def portable = this}
/**
* 使用type可以根据当前情况转化类型实现链式编程
*/
class Car{def run : this.type = this}
class Roadster extends Car{def luxury : this.type = this}
object Lsbc {
def main (args: Array[String]) {
val pc = new PC()
//pc.code.portable // Cannot resolve symbol portable
val roadster = new Roadster()
roadster.run.luxury
}
}