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
290
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
Netty Chicago Java User Group 2024-04-17
sullis
0
110
Java 21 - Portland Java User Group 2023-10-24
sullis
0
230
Microbenchmarking with JMH - Portland 2023-03-14
sullis
0
95
Code generation on the Java VM 2022-04-19
sullis
0
80
Mockito 2022-01-25
sullis
0
150
GitHub Actions 2021-12-16
sullis
0
28
Apache Struts and the Equifax data breach 2021-06-03
sullis
0
45
Guardrail State of the Union 2021-04-13
sullis
0
270
Guardrail: State of the Union 2021-03-18
sullis
0
140
Other Decks in Programming
See All in Programming
Git Lint
bkuhlmann
4
740
puregoの活用例
aethiopicuschan
0
220
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
110
CircleCIを活用して AWSへの継続的デリバリーを 実践する
coconala_engineer
1
230
HUIT新歓2024「競技プログラミング、やってみませんか?」
slephy2784
1
250
コードレビューで学ぶ!Kotlinオブジェクト指向デザインパターン
akkie76
2
180
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.2k
Ruby Function Composition
bkuhlmann
1
330
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
160
雑に思考を整理する技術と効能
konifar
55
25k
[SF Ruby, March 2024] Rails on Wasm
palkan
0
370
Code Reviews
bkuhlmann
4
880
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
123
8.5k
It's Worth the Effort
3n
180
27k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
A Modern Web Designer's Workflow
chriscoyier
688
190k
Optimizing for Happiness
mojombo
370
69k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
12
1.5k
The Language of Interfaces
destraynor
151
23k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Designing the Hi-DPI Web
ddemaree
276
33k
Writing Fast Ruby
sferik
620
60k
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