scala
xuelanghu407
纵使前途渺茫,也不能阻止我前进的脚步,怀着无限的热爱,投入到无限的ACM,即使是遍体鳞伤,也无后悔之心,毕竟曾经为着一个理想、目标奋斗过。
展开
-
Dynamic Invocation in Scala
import scala.language.dynamicsclass DynamicPerson extends Dynamic{ def selectDynamic(key:String):Any = { println(s"field '$key' selected") } def updateDynamic(key:String)(args:Any) = { pri原创 2016-07-30 09:55:08 · 381 阅读 · 0 评论 -
Args in class constructor
class Person (name:String, val age:Int, private val sex:Boolean) { def getName = { name } def getSex = { sex match { case true => "Boy" case false => "girl" } } }scala> v原创 2016-07-30 17:40:46 · 726 阅读 · 0 评论 -
Implicit conversions
class A { def m (key:Int): Unit = { println(s"Calling the method m in Class A with key value $key") } }implicit class B (a: A) { println("implicit transform Class A to Class B") def f (str:原创 2016-07-30 18:03:41 · 530 阅读 · 0 评论 -
Structural Types
// -- if it walks like a duck and talks like a duck, it must be a duck def f (eater: {def eat(s:String):String}) (food:String) { println(eater.eat(food)) }class Dog { def eat (food:String):String =原创 2016-08-01 15:41:04 · 438 阅读 · 0 评论 -
override ?
// ----------------------------------------------------------------------------- class A { def f(a:Int):Int = a + 3 } class B extends A{ val f = 2 } scala> val b= new B b: B = B@6990bf8dscala> b.f原创 2016-08-13 18:05:34 · 337 阅读 · 0 评论