A Postfunctional
Programming Language
on Java Virtual Machine
Compile to
JVM .class Byte Code
理論上
Full Java
Interoperability
可以直接拿來寫
Android Application
What is Scala?
A Scalable Language
會隨 User 變形的程式語言
A Scalable Language
A Scalable Language
Why Scala?
三個願望一次滿足
REPL
Scripting
Compiling
REPL
Scripting
Compiling
三個願望一次滿足
Procedure
Object Oriented
Functional
Procedure Programming
Object Oriented Programming
Functional Programming
三個願望一次滿足
Concise
Static Typing
Duck Typing
Concise (Ruby)
Concise (Scala)
Static Typing (Ruby)
Static Typing (Scala)
真、 Duck Typing (Ruby)
偽‧ Duck Typing (Scala)
結論
有 Scala 、無懦夫
僕我 用
了最
Scala
!喜
歡
女
寫
全我
都要
是萌
是讓
女手
燃程
僕上
!機
的式
Scala vs Java
Scala compared to Java
Scala adds Scala removes
+ a pure object system - static members
+ operator overloading - primitive types
+ closures - break, continue
+ mixin composition with traits - special treatment of interfaces
+ existential types - wildcards
+ abstract types - raw types
+ pattern matching - enums
Modeled in libraries:
assert, enums, properties, events, actors, using, queries, …
Scala cheat sheet (1): Definitions
Scala method definitions: Java method definition:
def fun(x: Int): Int = { int fun(int x) {
result return result
} }
def fun = result (no parameterless methods)
Scala variable definitions: Java variable definitions:
var x: Int = expression int x = expression
val x: String = expression final String x = expression
Scala cheat sheet (2): Expressions
Scala method calls: Java method call:
obj.meth(arg) obj.meth(arg)
obj meth arg (no operator overloading)
Scala choice expressions:
Java choice expressions, stmts:
if (cond) expr1 else expr2
cond ? expr1 : expr2
if (cond) return expr1;
else return expr2;
expr match {
case pat1 => expr1
switch (expr) {
.... case pat1 : return expr1;
case patn => exprn ...
} case patn : return exprn ;
} // statement only
Scala cheat sheet (3): Objects and Classes
Scala Class and Object Java Class with statics
class Sample {
class Sample(x: Int, val p: Int) { private final int x;
def instMeth(y: Int) = x + y public final int p;
} Sample(int x, int p) {
this.x = x;
object Sample { this.p = p;
def staticMeth(x: Int, y: Int) = }
x*y int instMeth(int y) {
} return x + y;
}
static int staticMeth(int x, int y) {
return x * y;
}
}
Scala cheat sheet (4): Traits
Java Interface
Scala Trait
trait T { interface T {
int abstractMth(String x)
def abstractMth(x: String): Int
}
def concreteMth(x: String) =
x + field (no concrete methods)
var field = “!”
(no fields)
}
Java extension + implementation:
Scala mixin composition:
class C extends Super implements T
class C extends Super with T
當機器人爬上樓梯
Android Application
開發流程
Java / ANT
$ android create project -p …
$ vim .....
$ ant install
1–1 of 1 previous next