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
Dependency management for Java applications 2025-09-11
sullis
0
14
S3 NYC Iceberg meetup 2025-07-10
sullis
0
43
Amazon S3 Chicago 2025-06-04
sullis
0
110
Amazon S3 Boston 2025-05-07
sullis
0
60
Netty ConFoo Montreal 2025-02-27
sullis
0
110
GitHub Actions ConFoo Montreal 2025-02-26
sullis
0
69
Netty Portland Java User Group 2025-02-18
sullis
0
15
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
190
Amazon S3 - Portland Java User Group 2024-09-17
sullis
0
120
Other Decks in Programming
See All in Programming
PHPに関数型の魂を宿す〜PHP 8.5 で実現する堅牢なコードとは〜 #phpcon_hiroshima / phpcon-hiroshima-2025
shogogg
1
220
CSC509 Lecture 04
javiergs
PRO
0
300
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
370
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
340
バッチ処理を「状態の記録」から「事実の記録」へ
panda728
PRO
0
160
登壇は dynamic! な営みである / speech is dynamic
da1chi
0
340
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
220
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
110
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
250
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
10
6.7k
Android16 Migration Stories ~Building a Pattern for Android OS upgrades~
reoandroider
0
110
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
21k
A Tale of Four Properties
chriscoyier
161
23k
Docker and Python
trallard
46
3.6k
Being A Developer After 40
akosma
91
590k
The Power of CSS Pseudo Elements
geoffreycrofte
79
6k
Writing Fast Ruby
sferik
629
62k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
189
55k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
Designing for humans not robots
tammielis
254
26k
Git: the NoSQL Database
bkeepers
PRO
431
66k
The Invisible Side of Design
smashingmag
302
51k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
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