]>
Scala Definitions |
|
trait A extends B with C1 ... with Cn { ... } |
(monomorphic) trait
|
abstract class A extends B with C1 ... with Cn { ... } |
(monomorphic) class (with nullary constructor)
|
class A(a1:T1,...,an:Tn*) ... |
class with n-ary constructor (rest as above) |
case class A(a1:T1,...,an:Tn*) ... |
case class with n-ary constructor (rest as above)
|
class A[X,Y] ... |
polymorphic class (== with type parameters) (rest as above)
|
object A extends B { ... } |
object definition
|
override def m(a1: T1,...,an: Tn*): T = { ... } |
method definition
|
def m(a1: T1,...,an: Tn): T; |
abstract method definition |
def m[X,Y](a1: T1,...,an: Tn) ... |
polymorphic method definition
|
override val x : T = e; |
value definition
|
val x: T; |
abstract value definition |
var x : T = e; |
variable definition, type T inferred if missing
|
Scala Constructs |
|
new Foo(...) |
new instance of Foo
|
if (cond) { e1 } else { e2 } |
if-then-else
|
for(val x: T <- e1) yield { e2 } |
for-comprehension, type T might be inferred from e1
|
while (cond) { ... }; do {...} while (cond); x = e; |
The usual stuff. Assignment works only for variables. |
e match { case p1 => e1 . . . case pN => eN case _ => eElse } |
Pattern match.
|
try { e } catch { case p1 => e1 . . . case pN => eN case _ => eElse } |
try-catch
|
Patterns |