Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Java-Scala interoperability - April 2016
Search
sullis
April 19, 2016
Programming
0
360
Java-Scala interoperability - April 2016
Java-Scala interoperability
Portland Java User Group
April 19, 2016
sullis
April 19, 2016
Tweet
Share
More Decks by sullis
See All by sullis
Amazon S3 Chicago 2025-06-04
sullis
0
86
Amazon S3 Boston 2025-05-07
sullis
0
40
Netty ConFoo Montreal 2025-02-27
sullis
0
70
GitHub Actions ConFoo Montreal 2025-02-26
sullis
0
41
Netty Portland Java User Group 2025-02-18
sullis
0
8
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
170
Amazon S3 - Portland Java User Group 2024-09-17
sullis
0
94
Netty - Montreal Java User Group 2024-05-21
sullis
0
170
Netty Chicago Java User Group 2024-04-17
sullis
0
1.1k
Other Decks in Programming
See All in Programming
Practical Tips and Tricks for Working with Compose Multiplatform Previews (mDevCamp 2025)
stewemetal
0
120
Go Modules: From Basics to Beyond / Go Modulesの基本とその先へ
kuro_kurorrr
0
120
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
1
780
C++20 射影変換
faithandbrave
0
490
エラーって何種類あるの?
kajitack
5
160
從零到一:搭建你的第一個 Observability 平台
blueswen
1
950
TypeScript LSP の今までとこれから
quramy
1
510
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
380
Select API from Kotlin Coroutine
jmatsu
1
170
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
230
実践ArchUnit ~実例による検証パターンの紹介~
ogiwarat
2
270
Development of an App for Intuitive AI Learning - Blockly Summit 2025
teba_eleven
0
120
Featured
See All Featured
A Tale of Four Properties
chriscoyier
159
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
RailsConf 2023
tenderlove
30
1.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.8k
Visualization
eitanlees
146
16k
A designer walks into a library…
pauljervisheath
206
24k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
The Invisible Side of Design
smashingmag
299
51k
BBQ
matthewcrist
89
9.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Transcript
Java-Scala interoperability Sean Sullivan April 19, 2016 Portland Java User
Group
• software engineer • 20 years Java • 5 years
at Gilt • back office systems @ Gilt About me
• Scala @ Gilt.com • Scala on the Java VM
• code examples Agenda
www.gilt.com
https://www.gilt.com/checkout
None
“The Scala 2.11.x series targets Java 6" http://www.scala-lang.org/news/2.11.0/
http://scala-lang.org/news/2.12-roadmap/ “The official Scala 2.12 distribution will be built for
Java 8 (and thus require it)”
Scala case classes and JSP’s
case class Thing( name: String, color: String)
thing.jsp <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <body> <c:out value=“${myThing.name}”/>
</body> </html>
JSP expression language expects a JavaBean with “getter” methods
import scala.reflect.BeanProperty case class Thing( @BeanProperty name: String, @BeanProperty color:
String) @BeanProperty annotation
Collections
None
• convert java.util.List to Scala collection • convert java.util.Set to
Scala collection • convert java.util.Map to Scala collection • convert Scala List to java.util.List Common scenarios
import scala.collection.JavaConverters._
import java.util.{ArrayList => JArrayList} import scala.collection.JavaConverters._ val jArrayList =
new JArrayList[String] jArrayList.add("a") jArrayList.add("b") jArrayList.add("c") val scalaList = jArrayList.asScala scalaList should be (List("a", "b", "c"))
Google Guava library
• com.google.common.base.Optional • com.google.common.util.concurrent.ListenableFuture
Guava @ Gilt
Guava Optional -> Scala Option Scala Option -> Guava Optional
import com.gilt.gfc.guava.GuavaConverters._
Guava Future -> Scala Future Scala Future -> Guava Future
import com.gilt.gfc.guava.future.FutureConverters._
Java 8
https://github.com/scala/scala-java8-compat
import scala.compat.java8.FutureConverters._ Java 8 Future to Scala Future
import scala.compat.java8.OptionConverters._ java.util.Optional to scala.Option
https://github.com/sullis/java-scala-interop-examples
The end
None