加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala链式编程内幕

发布时间:2020-12-16 09:01:15 所属栏目:安全 来源:网络整理
导读:1 package big.data.analyse.scala 2 3 /** 4 * 链式编程原理 5 * Created by zhen on 2018/12/16. 6 */ 7 class Computer{def code = this } 8 class PC extends Computer{def portable = this } 9 /** 10 * 使用type可以根据当前情况转化类型实现链式编程
 1 package big.data.analyse.scala
 2 
 3 /**
 4   * 链式编程原理
 5   * Created by zhen on 2018/12/16.
 6   */
 7 class Computer{def code = this}
 8 class PC extends Computer{def portable = this}
 9 /**
10   * 使用type可以根据当前情况转化类型实现链式编程
11   */
12 class Car{def run : this.type = this}
13 class Roadster extends Car{def luxury : this.type = this}
14 object Lsbc {
15   def main (args: Array[String]) {
16     val pc = new PC()
17     //pc.code.portable // Cannot resolve symbol portable
18     val roadster = new Roadster()
19     roadster.run.luxury
20   }
21 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读