Scala Introduction for Java developers
- ScalaMatsuri 2017
prerequisites
- JDK 8+ (if you'd like to use the latest Scala)
brew install sbt
to install the global sbt launcher script
scala lang version
You can switch the version when starting the JVM.
- 2.11.x on Java 7
- 2.11.x on Java 8
- 2.12.x on Java 8
Scala lang binary version
Binary compatibilities are not kept between the bin versions.
- 2.9.0
- 2.9.1
- 2.9.2
- 2.10.x
- 2.11.x
- 2.12.x
- 2.13.x
Getting started
- on the REPL: sbt console
- Setup Atom + ENSIME (in Japanese): https://gist.github.com/seratch/cc472f64f72ba725360ee6517008e23c
- IntelliJ IDEA (preparing sbt project and load it)
IntelliJ Setup Demo
# brew install sbt
mkdir -p hello-scala/project
cd hello-scala
echo 'sbt.version=0.13.13' > project/build.properties
echo 'scalaVersion := "2.12.1"' > build.sbt
sbt
Hello World
on the REPL
sbt console
# println("Hello World")
IntelliJ IDEA
- Run
- Debug
object Example extends App {
println("Hello World!")
}
diff java scala
- package, package object, import renamed package/class/trait
- Immutable Collection, Option
- class, trait, object
- companion object for static things
- test (ScalaTest, specs2)
Test Demo
echo 'libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"' >> build.sbt
Other Links
- http://skinny-framework.org/
- http://scalikejdbc.org/
- Java エンジニアチームが始めやすい Scala コーディングスタイル: https://www.slideshare.net/seratch/java-scala-ichigayageek