scala 课堂学习笔记

【声明】本文为AdamsLee原创,转载请注明出自围炉网并保留本文有效链接:scala 课堂学习笔记, 转载请保留本声明!
  • on JVM seamless interoperability with JAVA
  • static, strong typing
  • object == singleton ??
  • function definitions:

def fun(x: Int): Int = 

result 

}

def fun = result

  • function calls

obj meth arg # only one arg

  • Call By Value(CBV)  vs  Call By Name(CBN)

def func(x: Int, y:Int) =x*x

func ( 2+2, deadloop)

def func(x:Int, y: => Int)         y: => Int Call by name , default CBV

  • scala/match

never fall through next case

  • pattern types

constant ==

variable  every value, refers to the value in the right hand side

wildcard _

  • 大写 默认认为 常量    否则用`pi`
  • Pattern Guard

case p if guard => expr

Constructor Pattern

  • case class

a factory method

immutable arguments

toString/hashCode/equals

copy

  • sealed Class

To make the superclass of case classes sealed.

A sealed class cannot have any new subclasses added except the ones in the same file.

You only need to worry about the subclasses you already know about.

definition of HOF high order function

there can be up to 22 parameters in the function

  • anonymous function

var f1=(x:Int) => x*x

var f2:Int=>Int = x => x*x

sum((x:Int)=>2*x,a,b)

->sum(x=>x*x,a,b)

->sum(2*_,a,b)  _与函数列表一一对应

  • curring 多参数列表
  • Operators

alphanumeric (including "_")

symbolic

alphanumeric_symbolic

def unary_!=

only +-!~ can be unary!

  • class trait extends with
  • object acts like static or singleton, you can invoke a method directly from an object without "new"
  • 伴生对象

class A {}

object A {}

  • Important Types

Any, AnyRef(java.lang.Object), ScalaObject, AnyVal

Type Nothing

{throw exception} is of type Nothing

useful for empty collections

Null Type

null 

  • List are immutable
  • List

a +: b

a :+ b

  • stream — delay evaluation / lazy evalution

lazy val  VS val VS def

  • partial function
  • actors  receive 

while vs loop

you can treat every native thread as actor

react

  • SBT (simple build tool)

manage dependencies     maven ivy?

typesafe.com

  

此条目发表在未分类分类目录,贴了标签。将固定链接加入收藏夹。