你的位置:首页 > 软件开发 > 数据库 > scala学习

scala学习

发布时间:2016-03-02 17:00:09
1、鸭子类型,走起来像鸭子,叫起来像鸭子,就是鸭子。函数中使用{ def close(): Unit }作为参数类型,因此任何含有此函数的类都可以作为参数传递。好处是不必使用继承特性。 1 def withClose(closeAble: { def close(): Unit ...

1、鸭子类型,走起来像鸭子,叫起来像鸭子,就是鸭子。函数中使用{ def close(): Unit }作为参数类型,因此任何含有此函数的类都可以作为参数传递。好处是不必使用继承特性。

 1 def withClose(closeAble: { def close(): Unit },  2   op: { def close(): Unit } => Unit) { 3   try { 4     op(closeAble) 5   } finally { 6     closeAble.close() 7   } 8 } 9 10 class Connection {11   def close() = println("close Connection")12 }13 14 val conn: Connection = new Connection()15 withClose(conn, conn =>16   println("do something with Connection"))

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:scala学习

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录