SlideShare a Scribd company logo
1 of 18
Download to read offline
From Java to Kotlin
The first months in practice
22. Mar 2018
Agenda
What to expect today?
My Background
Why Kotlin?
Live-Coding:
Convert Spring Boot
App
Summary
My Background
solution-oriented
developer
>10 years Java
7 month @
Meshcloud
Why Kotlin?
Expressive
100% Java
interoperability
Developed by JetBrains,
Open Source
-> great IDE support
Strictly-Typed
-> Null-Safety
Practical,
not academic
Demo time
Let’s get practical :)
https://github.com/Meshcloud/spring-kotlin-example
Demo Statistics
LoC
Java: 460
Kotlin: 252
Reduction: 46%
LoC without data classes
Java: 232
Kotlin: 185
Reduction: 21%
https://github.com/Meshcloud/spring-kotlin-example
Summary
All the cool things
we’ve just seen,
and a bit more,
on a few slides
1. Null-Safety
Null checks during compilation:
var x = “value”
x = null // compile error
Great support for
handling nullable values:
var x:MyClass?
val child = x?.child
Intelligent compiler:
if (x != null) {
val child = x.child
} Elvis Operator:
projectRepository.findOne(id)
?: throw NotFoundException()
Force not null:
val y: String = x!!
2. Mighty little helpers
String templates:
val text = "Project ${project.name} - ${project.description}"
Ranges
for (i in 1..100)
for (i in 10 downTo 1)
Structural equality with ==
project == otherProject // calls null-safe equals
project === otherProject // referential equality
Destructuring
for ((key, value) in map) {
print("Key: $key, Value: $value")
}
3. Avoid property boilerplate
Data classes (with equals, hashcode, toString & copy):
data class Project(
val name: String,
val description: String,
val fullText: String
get() = “$name - $description”
)
Implicit Getters/Setters & property access:
class Project {
var name: String
}
Project().name
4. Expressive arguments
Default Arguments:
fun create(
name: String,
description: String = “default”
)
Named Arguments
create(
name = “My Project”,
description = “Some details”
)
Apply method:
Project().apply(
name = “My Project”
description = “Some details”
)
5. Higher-Order Functions
Java (Function, Consumer, Supplier, BiConsumer, …):
public String myFunction(
BiFunction<String, String, String> fn
)
fn.apply(“1”, “2”) // .get() on Supplier, ...
Kotlin:
fun myFunction(
fn: (String, String) -> String
)
fn(“1”, “2”)
6. Concise Streaming API
Java:
projectRepository
.findAll()
.stream()
.map(p -> new ProjectListDTO(p))
.collect(Collectors.toList());
Kotlin:
projectRepository
.findAll()
.map { ProjectListDTO(it)}
7. Reduce the overhead
Type Inference:
Map<ResourceType, List<Resource>> resourceMapByType =
service.findResourceMapByType(); // Java
val resourceMapByType = service.findResourceMapByType() // Kotlin
Smart Casts:
if (obj is Project) {
print(obj.description) // obj is now known to be a Project
}
When Expressions:
when {
"Bitcoin" in projectNames -> println("Bad guy!")
projectNames is empty -> println("No Projects")
else -> println("Just normal projects!")
}
8. Further concepts in Kotlin
Coroutines:
// experimental simplified non-blocking IO async implementation
async {
doSomething(foo)
...
}
Operator Overloading:
data class Vec(val x: Float, val y: Float) {
operator fun plus(v: Vec) = Vec(x + v.x, y + v.y)
}
val v = Vec(2f, 3f) + Vec(4f, 1f)
Questions?
Contacts
Stefan Tomm <stomm@meshcloud.io>
Johannes Rudolph <jrudolph@meshcloud.io>
www.meshcloud.io
@meshstack
@meshstack
https://kotlinlang.org/
SDR ResourceProcessors
Controller with nullable param:
class ProjectController {
@GetMapping
open fun findAllOwnedByCurrentUser(principal: Principal?) {
principal!!
...
}
}
ResourceProcessor using null params
@Component
class ProjectResourceProcessor: ResourceProcessor<Resource<Project>> {
override fun process(resource: Resource<Customer>): Resource<Project>
{
resource.add(linkTo(methodOn(ProjectController::class.java)
.findAllOwnedByCurrentUser(null)).withRel("ownedProjects"))
}
}
Repo Queries with raw strings
@Query("""
SELECT o FROM #{#entityName} o
WHERE (o.email LIKE %:searchTerm% OR o.username LIKE %:searchTerm% OR o.name LIKE %:searchTerm%)
AND (
(
?#{principal.customer.id} IN (SELECT customer.id FROM CustomerUserGroup WHERE user.id = o.id)
OR ?#{principal.customer.id} IN (SELECT partner.id FROM CustomerUserGroup WHERE user.id = o.id)
)
AND 1 = ?#{ hasAuthority('USER_LIST') ? 1 : 0 }
OR 1 = ?#{ hasAuthority('ADM_USER_LIST') ? 1 : 0 }
)
""")

More Related Content

What's hot

Accumulo Summit 2014: Accumulo backed Tinkerpop Implementation
Accumulo Summit 2014: Accumulo backed Tinkerpop ImplementationAccumulo Summit 2014: Accumulo backed Tinkerpop Implementation
Accumulo Summit 2014: Accumulo backed Tinkerpop Implementation
Accumulo Summit
 
2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python
Adam Hitchcock
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
Jerry Chou
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
Andrzej Sitek
 

What's hot (20)

My Gentle Introduction to RxJS
My Gentle Introduction to RxJSMy Gentle Introduction to RxJS
My Gentle Introduction to RxJS
 
Accumulo Summit 2014: Accumulo backed Tinkerpop Implementation
Accumulo Summit 2014: Accumulo backed Tinkerpop ImplementationAccumulo Summit 2014: Accumulo backed Tinkerpop Implementation
Accumulo Summit 2014: Accumulo backed Tinkerpop Implementation
 
2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScript
 
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
 
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
 
Joblib for cloud computing
Joblib for cloud computingJoblib for cloud computing
Joblib for cloud computing
 
Asset Bundleちょっと理解した( )
Asset Bundleちょっと理解した( )Asset Bundleちょっと理解した( )
Asset Bundleちょっと理解した( )
 
Kopf @ Python Pizza Berlin, 2019-08-23
Kopf @ Python Pizza Berlin, 2019-08-23Kopf @ Python Pizza Berlin, 2019-08-23
Kopf @ Python Pizza Berlin, 2019-08-23
 
SFScon19 - Luca Romano Simone Vianello - ORM and RDBMS, how to make them work...
SFScon19 - Luca Romano Simone Vianello - ORM and RDBMS, how to make them work...SFScon19 - Luca Romano Simone Vianello - ORM and RDBMS, how to make them work...
SFScon19 - Luca Romano Simone Vianello - ORM and RDBMS, how to make them work...
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
 
V8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーV8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパー
 
• GUI design using drag and drop feature of IDE(Net beans), • File IO
•	GUI design using drag and drop feature of IDE(Net beans), •	File IO•	GUI design using drag and drop feature of IDE(Net beans), •	File IO
• GUI design using drag and drop feature of IDE(Net beans), • File IO
 
Reactive Extensions for JavaScript
Reactive Extensions for JavaScriptReactive Extensions for JavaScript
Reactive Extensions for JavaScript
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
JavaScript Reactivity - Angular Meetup Dhaka
JavaScript Reactivity - Angular Meetup DhakaJavaScript Reactivity - Angular Meetup Dhaka
JavaScript Reactivity - Angular Meetup Dhaka
 
Reactive Programming and RxJS
Reactive Programming and RxJSReactive Programming and RxJS
Reactive Programming and RxJS
 
24 Weeks at AdroitLogic - My Internship Experience
24 Weeks at AdroitLogic - My Internship Experience24 Weeks at AdroitLogic - My Internship Experience
24 Weeks at AdroitLogic - My Internship Experience
 

Similar to From Java to Kotlin - The first month in practice v2

Similar to From Java to Kotlin - The first month in practice v2 (20)

From Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceFrom Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practice
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
 
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
 
Why kotlininandroid
Why kotlininandroidWhy kotlininandroid
Why kotlininandroid
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
JSAnkara Swift v React Native
JSAnkara Swift v React NativeJSAnkara Swift v React Native
JSAnkara Swift v React Native
 
Kotlin/Everywhere GDG Bhubaneswar 2019
Kotlin/Everywhere GDG Bhubaneswar 2019 Kotlin/Everywhere GDG Bhubaneswar 2019
Kotlin/Everywhere GDG Bhubaneswar 2019
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlin
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
Play framework
Play frameworkPlay framework
Play framework
 
Kubernetes + Python = ❤ - Cloud Native Prague
Kubernetes + Python = ❤ - Cloud Native PragueKubernetes + Python = ❤ - Cloud Native Prague
Kubernetes + Python = ❤ - Cloud Native Prague
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOPHOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
 
droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutines
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
 
Kotlin. One language to dominate them all.
Kotlin. One language to dominate them all.Kotlin. One language to dominate them all.
Kotlin. One language to dominate them all.
 

Recently uploaded

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Recently uploaded (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 

From Java to Kotlin - The first month in practice v2

  • 1. From Java to Kotlin The first months in practice 22. Mar 2018
  • 2. Agenda What to expect today? My Background Why Kotlin? Live-Coding: Convert Spring Boot App Summary
  • 4. Why Kotlin? Expressive 100% Java interoperability Developed by JetBrains, Open Source -> great IDE support Strictly-Typed -> Null-Safety Practical, not academic
  • 5. Demo time Let’s get practical :) https://github.com/Meshcloud/spring-kotlin-example
  • 6. Demo Statistics LoC Java: 460 Kotlin: 252 Reduction: 46% LoC without data classes Java: 232 Kotlin: 185 Reduction: 21% https://github.com/Meshcloud/spring-kotlin-example
  • 7. Summary All the cool things we’ve just seen, and a bit more, on a few slides
  • 8. 1. Null-Safety Null checks during compilation: var x = “value” x = null // compile error Great support for handling nullable values: var x:MyClass? val child = x?.child Intelligent compiler: if (x != null) { val child = x.child } Elvis Operator: projectRepository.findOne(id) ?: throw NotFoundException() Force not null: val y: String = x!!
  • 9. 2. Mighty little helpers String templates: val text = "Project ${project.name} - ${project.description}" Ranges for (i in 1..100) for (i in 10 downTo 1) Structural equality with == project == otherProject // calls null-safe equals project === otherProject // referential equality Destructuring for ((key, value) in map) { print("Key: $key, Value: $value") }
  • 10. 3. Avoid property boilerplate Data classes (with equals, hashcode, toString & copy): data class Project( val name: String, val description: String, val fullText: String get() = “$name - $description” ) Implicit Getters/Setters & property access: class Project { var name: String } Project().name
  • 11. 4. Expressive arguments Default Arguments: fun create( name: String, description: String = “default” ) Named Arguments create( name = “My Project”, description = “Some details” ) Apply method: Project().apply( name = “My Project” description = “Some details” )
  • 12. 5. Higher-Order Functions Java (Function, Consumer, Supplier, BiConsumer, …): public String myFunction( BiFunction<String, String, String> fn ) fn.apply(“1”, “2”) // .get() on Supplier, ... Kotlin: fun myFunction( fn: (String, String) -> String ) fn(“1”, “2”)
  • 13. 6. Concise Streaming API Java: projectRepository .findAll() .stream() .map(p -> new ProjectListDTO(p)) .collect(Collectors.toList()); Kotlin: projectRepository .findAll() .map { ProjectListDTO(it)}
  • 14. 7. Reduce the overhead Type Inference: Map<ResourceType, List<Resource>> resourceMapByType = service.findResourceMapByType(); // Java val resourceMapByType = service.findResourceMapByType() // Kotlin Smart Casts: if (obj is Project) { print(obj.description) // obj is now known to be a Project } When Expressions: when { "Bitcoin" in projectNames -> println("Bad guy!") projectNames is empty -> println("No Projects") else -> println("Just normal projects!") }
  • 15. 8. Further concepts in Kotlin Coroutines: // experimental simplified non-blocking IO async implementation async { doSomething(foo) ... } Operator Overloading: data class Vec(val x: Float, val y: Float) { operator fun plus(v: Vec) = Vec(x + v.x, y + v.y) } val v = Vec(2f, 3f) + Vec(4f, 1f)
  • 16. Questions? Contacts Stefan Tomm <stomm@meshcloud.io> Johannes Rudolph <jrudolph@meshcloud.io> www.meshcloud.io @meshstack @meshstack https://kotlinlang.org/
  • 17. SDR ResourceProcessors Controller with nullable param: class ProjectController { @GetMapping open fun findAllOwnedByCurrentUser(principal: Principal?) { principal!! ... } } ResourceProcessor using null params @Component class ProjectResourceProcessor: ResourceProcessor<Resource<Project>> { override fun process(resource: Resource<Customer>): Resource<Project> { resource.add(linkTo(methodOn(ProjectController::class.java) .findAllOwnedByCurrentUser(null)).withRel("ownedProjects")) } }
  • 18. Repo Queries with raw strings @Query(""" SELECT o FROM #{#entityName} o WHERE (o.email LIKE %:searchTerm% OR o.username LIKE %:searchTerm% OR o.name LIKE %:searchTerm%) AND ( ( ?#{principal.customer.id} IN (SELECT customer.id FROM CustomerUserGroup WHERE user.id = o.id) OR ?#{principal.customer.id} IN (SELECT partner.id FROM CustomerUserGroup WHERE user.id = o.id) ) AND 1 = ?#{ hasAuthority('USER_LIST') ? 1 : 0 } OR 1 = ?#{ hasAuthority('ADM_USER_LIST') ? 1 : 0 } ) """)