SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Kotlin 1.2
Sharing Code Between Platforms
Kirill Rozov
Android Developer
Kotlin Achievements
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
• More than 17% projects in Android Studio 3.0
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
• More than 17% projects in Android Studio 3.0
• Support in Spring 5.0
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
• More than 17% projects in Android Studio 3.0
• Support in Spring 5.0
• Gradle Kotlin DSL
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
• More than 17% projects in Android Studio 3.0
• Support in Spring 5.0
• Gradle Kotlin DSL
• Fastest-growing and one of the least-disliked languages*
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
• More than 17% projects in Android Studio 3.0
• Support in Spring 5.0
• Gradle Kotlin DSL
• Fastest-growing and one of the least-disliked languages*
• Support of JVM, JS, Native**
* Based on information from Stackoverflow

** In development
Kotlin Achievements
• Official language on Android
• More than 17% projects in Android Studio 3.0
• Support in Spring 5.0
• Gradle Kotlin DSL
• Fastest-growing and one of the least-disliked languages*
• Support of JVM, JS, Native**
• Kotlin Conf
* Based on information from Stackoverflow

** In development
Kotlin Popularity
1.11.0
Language
syntax
Array literals
// Kotlin 1.1
@CacheConfig(cacheNames = arrayOf("books", "default"))
class BookRepository
Array literals
// Kotlin 1.1
@CacheConfig(cacheNames = arrayOf("books", "default"))
class BookRepository
The array literal syntax is constrained to annotation arguments
// Kotlin 1.2
@CacheConfig(cacheNames = ["books", “default"])
class BookRepository
lateinit
lateinit var lateinitVar: String
// ‘false’
println("isInitialized: " + this::lateinitVar.isInitialized)
lateinitVar = "value"
// ‘true’
println("isInitialized: " + this::lateinitVar.isInitialized)
lateinit
• Possibility to check whether lateinit variable is initialized
• Support on top-level properties
• Support for local variables
Inline functions
// Kotlin 1.1
fun <E> Iterable<E>.strings() = strings { it.toString() }
inline fun <E> Iterable<E>.strings(transform: (E) -> String) =
map { transform(it) }
Inline functions
// Kotlin 1.1
fun <E> Iterable<E>.strings() = strings { it.toString() }
inline fun <E> Iterable<E>.strings(transform: (E) -> String) =
map { transform(it) }
// Kotlin 1.2
inline fun <E> Iterable<E>.strings(
transform: (E) -> String = { it.toString() }) =
map { transform(it) }
Casts improvements
// Kotlin 1.1
val button = findViewById<View>(R.id.button) as Button
Casts improvements
// Kotlin 1.1
val button = findViewById<View>(R.id.button) as Button
// Kotlin 1.2
val button = findViewById(R.id.button) as Button
Casts improvements
// Kotlin 1.1
val s : Any = …
val firstChar = (s as? CharSequence)?.firstOrNull()
if (firstChar != null) {
s as CharSequence
return s.count { it == firstChar }
}
Casts improvements
// Kotlin 1.2
if (firstChar != null) {
// s: Any is smart cast to CharSequence
return s.count { it == firstChar }
}
// Kotlin 1.1
val s : Any = …
val firstChar = (s as? CharSequence)?.firstOrNull()
if (firstChar != null) {
s as CharSequence
return s.count { it == firstChar }
}
Standard
library
Standard library
Standard library
• Compatibility with Java 9 module system
Java 9 Support
• Compatible with the Java 9 module system (Project Jigsaw)

New artifacts kotlin-stdlib-jdkN
• Deprecated declaration in kotlin.reflect package were
removed

Use declarations in kotlin.reflect.full package instead
Standard library
• Compatibility with Java 9 module system
Standard library
• Compatibility with Java 9 module system
• New extensions for collections
chuncked, windowed, zipWithNext
val items = listOf(1, 1, 2, 3)
Only for Iterable<T>, Sequence<T>, CharSequence
chuncked, windowed, zipWithNext
val items = listOf(1, 1, 2, 3)
items.chunked(3) // [[1, 1, 2], [3]]
Only for Iterable<T>, Sequence<T>, CharSequence
chuncked, windowed, zipWithNext
val items = listOf(1, 1, 2, 3)
items.chunked(3) // [[1, 1, 2], [3]]
items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)]
Only for Iterable<T>, Sequence<T>, CharSequence
chuncked, windowed, zipWithNext
val items = listOf(1, 1, 2, 3)
items.chunked(3) // [[1, 1, 2], [3]]
items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)]
items.windowed(2) // [[1, 1], [1, 2], [2, 3]]
Only for Iterable<T>, Sequence<T>, CharSequence
chuncked, windowed, zipWithNext
val items = listOf(1, 1, 2, 3)
items.chunked(3) // [[1, 1, 2], [3]]
items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)]
items.windowed(2) // [[1, 1], [1, 2], [2, 3]]
items.windowed(2) { it.average() } // [1, 1.5, 2.5]
Only for Iterable<T>, Sequence<T>, CharSequence
chuncked, windowed, zipWithNext
val items = listOf(1, 1, 2, 3)
items.chunked(3) // [[1, 1, 2], [3]]
items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)]
items.windowed(2) // [[1, 1], [1, 2], [2, 3]]
items.windowed(2) { it.average() } // [1, 1.5, 2.5]
items.zipWithNext { a, b -> b - a } // [0, 1, 1]
Only for Iterable<T>, Sequence<T>, CharSequence
fill, replaceAll, shuffle
val items = mutableListOf(0, 1, 2, 3, 5, 8)
Only for MutableList<T>
fill, replaceAll, shuffle
val items = mutableListOf(0, 1, 2, 3, 5, 8)
items.shuffle() // [3, 8, 5, 0, 2, 1]. Output can be different
Only for MutableList<T>
fill, replaceAll, shuffle
val items = mutableListOf(0, 1, 2, 3, 5, 8)
items.shuffle() // [3, 8, 5, 0, 2, 1]. Output can be different
items.replaceAll { it * 2 } // [0, 2, 4, 6, 10, 16]
Only for MutableList<T>
fill, replaceAll, shuffle
val items = mutableListOf(0, 1, 2, 3, 5, 8)
items.shuffle() // [3, 8, 5, 0, 2, 1]. Output can be different
items.replaceAll { it * 2 } // [0, 2, 4, 6, 10, 16]
items.fill(5) // [5, 5, 5, 5, 5, 5]
Only for MutableList<T>
Standard library
• Fully compatibility with Java 9 module system
• New extensions for collections
Standard library
• Fully compatibility with Java 9 module system
• New extensions for collections
• Math operations
Standard library
• Fully compatibility with Java 9 module system
• New extensions for collections
• Math operations
• Operators and conversions for BigInteger and BigDecimal
• Floating point to bits conversions
• Regex is now Serializable
• Closeable.use() calls Throwable.addSuppressed() (JDK 7+)
Java
• Constructor calls normalization
• Java-default methods calls
• Breaking changes:
• Consistent behaviour of x.equals(null) for platform types
• Added check of receiver in inline extension functions that
were called on a null value of a platform type
• Smart cast inside try block after the block made more strict
Deprecation
• Mutating backing field of read-only property
• Override copy() in data classes
• Not inner classes in enum entries
• Passing a single item for a vararg parameter in the named
form
• Inner classes of generic classes extending Throwable
Other
• Support for ::foo as a shorthand for this::foo
• JS TypedArrays support for Kotlin primitive array (IntArray,
FloatArray, etc) enabled by default
• The Kotlin compiler now provides an option to treat all
warnings as errors
• Support in Kotlin Native 0.4
Compilation Performance
Approximately 25% improvement over Kotlin 1.1
Multiplatform

projects
Multiplatform Projects
expect & actual
// expected platform-specific API
expect fun hello(world: String) Common
// actual JVM implementation
actual fun hello(world: String) =
println(“Hello, $world, on the JVM!") JVM
// actual JS implementation
actual fun hello(world: String) =
console.log("Hello, $world, on the JS!") JS
expect class Date() {
fun getDate(): Int
fun getMonth(): Int
} Common
actual class Date {
private val calendar: Calendar
actual constructor() {
calendar = Calendar.getInstance()
}
actual fun getDate() = calendar[DAY_OF_MONTH]
actual fun getMonth() = calendar[MONTH]
} JVM
actual external class Date {
actual fun getDate(): Int
actual fun getMonth(): Int
} JS
Common

module
Platform

module
Regular

module
Common

module
JVM
JS
//common-jvm/build.gradle
apply plugin:'kotlin-platform-jvm'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
expectedBy project(":common")
} JVM
//android/build.gradle
apply plugin: 'kotlin-android'
dependencies {
implementation project(":common-jvm")
} Android
//common/build.gradle
apply plugin: 'kotlin-platform-common'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
}
Common
Common modules
• Test

Run test both on Java & JS platforms
• Serialization

Marshal Kotlin objects between different tiers of your application, based on JSON or ProtoBuf as
serialization format
• HTML

The same code to render HTML in the backend and in the frontend
Future commons
• IO
• Networking (HTTP, TCP, etc.)
• Dates
Summary
Summary
• Allow to write parts of app in same language
Summary
• Allow to write parts of app in same language
• Interoperability on supported platforms
Summary
• Allow to write parts of app in same language
• Interoperability on supported platforms
• Shared business logic
Summary
• Allow to write parts of app in same language
• Interoperability on supported platforms
• Shared business logic
• UI is platform-specific
Summary
• Allow to write parts of app in same language
• Interoperability on supported platforms
• Shared business logic
• UI is platform-specific
• JVM/JS code reuse already worked, Native coming soon
Summary
• Allow to write parts of app in same language
• Interoperability on supported platforms
• Shared business logic
• UI is platform-specific
• JVM/JS code reuse already worked, Native coming soon
• Support of Multiplatform projects in IDEA 2017.3
Thanks
krl.rozov@gmail.com

Weitere ähnliche Inhalte

Was ist angesagt?

Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
Hiroshi Nakamura
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
.toster
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
Jason Grimes
 

Was ist angesagt? (20)

[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
 
運用 Exposed 管理及操作資料庫
運用 Exposed 管理及操作資料庫運用 Exposed 管理及操作資料庫
運用 Exposed 管理及操作資料庫
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
はじめてのSymfony2
はじめてのSymfony2はじめてのSymfony2
はじめてのSymfony2
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
Node.js streaming csv downloads proxy
Node.js streaming csv downloads proxyNode.js streaming csv downloads proxy
Node.js streaming csv downloads proxy
 
Javascript asynchronous
Javascript asynchronousJavascript asynchronous
Javascript asynchronous
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
用 OPENRNDR 將 Chatbot 訊息視覺化
用 OPENRNDR 將 Chatbot 訊息視覺化用 OPENRNDR 將 Chatbot 訊息視覺化
用 OPENRNDR 將 Chatbot 訊息視覺化
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema Ruby
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
 

Ähnlich wie Kotlin 1.2: Sharing code between platforms

Ähnlich wie Kotlin 1.2: Sharing code between platforms (20)

Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Hello kotlin | An Event by DSC Unideb
Hello kotlin | An Event by DSC UnidebHello kotlin | An Event by DSC Unideb
Hello kotlin | An Event by DSC Unideb
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Building android apps with kotlin
Building android apps with kotlinBuilding android apps with kotlin
Building android apps with kotlin
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 

Mehr von Kirill Rozov

Mehr von Kirill Rozov (20)

Kotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is comingKotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is coming
 
2 years without Java. Kotlin only
2 years without Java. Kotlin only2 years without Java. Kotlin only
2 years without Java. Kotlin only
 
Почему Kotlin?
Почему Kotlin?Почему Kotlin?
Почему Kotlin?
 
KOIN for dependency Injection
KOIN for dependency InjectionKOIN for dependency Injection
KOIN for dependency Injection
 
Optimize APK size
Optimize APK sizeOptimize APK size
Optimize APK size
 
ConstraintLayout. Fell the Power of constraints
ConstraintLayout. Fell the Power of constraintsConstraintLayout. Fell the Power of constraints
ConstraintLayout. Fell the Power of constraints
 
Kotlin - следующий язык после Java
Kotlin - следующий язык после JavaKotlin - следующий язык после Java
Kotlin - следующий язык после Java
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2
 
Что нового в Android O (Grodno HTP)
Что нового в Android O (Grodno HTP)Что нового в Android O (Grodno HTP)
Что нового в Android O (Grodno HTP)
 
What's new in Android O
What's new in Android OWhat's new in Android O
What's new in Android O
 
Android service
Android serviceAndroid service
Android service
 
Effective Java
Effective JavaEffective Java
Effective Java
 
Dagger 2
Dagger 2Dagger 2
Dagger 2
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
REST
RESTREST
REST
 
Kotlin для Android
Kotlin для AndroidKotlin для Android
Kotlin для Android
 
What's new in Android M
What's new in Android MWhat's new in Android M
What's new in Android M
 

Kürzlich hochgeladen

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Kürzlich hochgeladen (20)

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 

Kotlin 1.2: Sharing code between platforms

  • 1. Kotlin 1.2 Sharing Code Between Platforms Kirill Rozov Android Developer
  • 2. Kotlin Achievements * Based on information from Stackoverflow
 ** In development
  • 3. Kotlin Achievements • Official language on Android * Based on information from Stackoverflow
 ** In development
  • 4. Kotlin Achievements • Official language on Android • More than 17% projects in Android Studio 3.0 * Based on information from Stackoverflow
 ** In development
  • 5. Kotlin Achievements • Official language on Android • More than 17% projects in Android Studio 3.0 • Support in Spring 5.0 * Based on information from Stackoverflow
 ** In development
  • 6. Kotlin Achievements • Official language on Android • More than 17% projects in Android Studio 3.0 • Support in Spring 5.0 • Gradle Kotlin DSL * Based on information from Stackoverflow
 ** In development
  • 7. Kotlin Achievements • Official language on Android • More than 17% projects in Android Studio 3.0 • Support in Spring 5.0 • Gradle Kotlin DSL • Fastest-growing and one of the least-disliked languages* * Based on information from Stackoverflow
 ** In development
  • 8. Kotlin Achievements • Official language on Android • More than 17% projects in Android Studio 3.0 • Support in Spring 5.0 • Gradle Kotlin DSL • Fastest-growing and one of the least-disliked languages* • Support of JVM, JS, Native** * Based on information from Stackoverflow
 ** In development
  • 9. Kotlin Achievements • Official language on Android • More than 17% projects in Android Studio 3.0 • Support in Spring 5.0 • Gradle Kotlin DSL • Fastest-growing and one of the least-disliked languages* • Support of JVM, JS, Native** • Kotlin Conf * Based on information from Stackoverflow
 ** In development
  • 12. Array literals // Kotlin 1.1 @CacheConfig(cacheNames = arrayOf("books", "default")) class BookRepository
  • 13. Array literals // Kotlin 1.1 @CacheConfig(cacheNames = arrayOf("books", "default")) class BookRepository The array literal syntax is constrained to annotation arguments // Kotlin 1.2 @CacheConfig(cacheNames = ["books", “default"]) class BookRepository
  • 14. lateinit lateinit var lateinitVar: String // ‘false’ println("isInitialized: " + this::lateinitVar.isInitialized) lateinitVar = "value" // ‘true’ println("isInitialized: " + this::lateinitVar.isInitialized)
  • 15. lateinit • Possibility to check whether lateinit variable is initialized • Support on top-level properties • Support for local variables
  • 16. Inline functions // Kotlin 1.1 fun <E> Iterable<E>.strings() = strings { it.toString() } inline fun <E> Iterable<E>.strings(transform: (E) -> String) = map { transform(it) }
  • 17. Inline functions // Kotlin 1.1 fun <E> Iterable<E>.strings() = strings { it.toString() } inline fun <E> Iterable<E>.strings(transform: (E) -> String) = map { transform(it) } // Kotlin 1.2 inline fun <E> Iterable<E>.strings( transform: (E) -> String = { it.toString() }) = map { transform(it) }
  • 18. Casts improvements // Kotlin 1.1 val button = findViewById<View>(R.id.button) as Button
  • 19. Casts improvements // Kotlin 1.1 val button = findViewById<View>(R.id.button) as Button // Kotlin 1.2 val button = findViewById(R.id.button) as Button
  • 20. Casts improvements // Kotlin 1.1 val s : Any = … val firstChar = (s as? CharSequence)?.firstOrNull() if (firstChar != null) { s as CharSequence return s.count { it == firstChar } }
  • 21. Casts improvements // Kotlin 1.2 if (firstChar != null) { // s: Any is smart cast to CharSequence return s.count { it == firstChar } } // Kotlin 1.1 val s : Any = … val firstChar = (s as? CharSequence)?.firstOrNull() if (firstChar != null) { s as CharSequence return s.count { it == firstChar } }
  • 24. Standard library • Compatibility with Java 9 module system
  • 25. Java 9 Support • Compatible with the Java 9 module system (Project Jigsaw)
 New artifacts kotlin-stdlib-jdkN • Deprecated declaration in kotlin.reflect package were removed
 Use declarations in kotlin.reflect.full package instead
  • 26. Standard library • Compatibility with Java 9 module system
  • 27. Standard library • Compatibility with Java 9 module system • New extensions for collections
  • 28. chuncked, windowed, zipWithNext val items = listOf(1, 1, 2, 3) Only for Iterable<T>, Sequence<T>, CharSequence
  • 29. chuncked, windowed, zipWithNext val items = listOf(1, 1, 2, 3) items.chunked(3) // [[1, 1, 2], [3]] Only for Iterable<T>, Sequence<T>, CharSequence
  • 30. chuncked, windowed, zipWithNext val items = listOf(1, 1, 2, 3) items.chunked(3) // [[1, 1, 2], [3]] items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)] Only for Iterable<T>, Sequence<T>, CharSequence
  • 31. chuncked, windowed, zipWithNext val items = listOf(1, 1, 2, 3) items.chunked(3) // [[1, 1, 2], [3]] items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)] items.windowed(2) // [[1, 1], [1, 2], [2, 3]] Only for Iterable<T>, Sequence<T>, CharSequence
  • 32. chuncked, windowed, zipWithNext val items = listOf(1, 1, 2, 3) items.chunked(3) // [[1, 1, 2], [3]] items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)] items.windowed(2) // [[1, 1], [1, 2], [2, 3]] items.windowed(2) { it.average() } // [1, 1.5, 2.5] Only for Iterable<T>, Sequence<T>, CharSequence
  • 33. chuncked, windowed, zipWithNext val items = listOf(1, 1, 2, 3) items.chunked(3) // [[1, 1, 2], [3]] items.chunked(2) { (x, y) -> Pair(x, y) } // [(1, 1), (2, 3)] items.windowed(2) // [[1, 1], [1, 2], [2, 3]] items.windowed(2) { it.average() } // [1, 1.5, 2.5] items.zipWithNext { a, b -> b - a } // [0, 1, 1] Only for Iterable<T>, Sequence<T>, CharSequence
  • 34. fill, replaceAll, shuffle val items = mutableListOf(0, 1, 2, 3, 5, 8) Only for MutableList<T>
  • 35. fill, replaceAll, shuffle val items = mutableListOf(0, 1, 2, 3, 5, 8) items.shuffle() // [3, 8, 5, 0, 2, 1]. Output can be different Only for MutableList<T>
  • 36. fill, replaceAll, shuffle val items = mutableListOf(0, 1, 2, 3, 5, 8) items.shuffle() // [3, 8, 5, 0, 2, 1]. Output can be different items.replaceAll { it * 2 } // [0, 2, 4, 6, 10, 16] Only for MutableList<T>
  • 37. fill, replaceAll, shuffle val items = mutableListOf(0, 1, 2, 3, 5, 8) items.shuffle() // [3, 8, 5, 0, 2, 1]. Output can be different items.replaceAll { it * 2 } // [0, 2, 4, 6, 10, 16] items.fill(5) // [5, 5, 5, 5, 5, 5] Only for MutableList<T>
  • 38. Standard library • Fully compatibility with Java 9 module system • New extensions for collections
  • 39. Standard library • Fully compatibility with Java 9 module system • New extensions for collections • Math operations
  • 40. Standard library • Fully compatibility with Java 9 module system • New extensions for collections • Math operations • Operators and conversions for BigInteger and BigDecimal • Floating point to bits conversions • Regex is now Serializable • Closeable.use() calls Throwable.addSuppressed() (JDK 7+)
  • 41. Java • Constructor calls normalization • Java-default methods calls • Breaking changes: • Consistent behaviour of x.equals(null) for platform types • Added check of receiver in inline extension functions that were called on a null value of a platform type • Smart cast inside try block after the block made more strict
  • 42. Deprecation • Mutating backing field of read-only property • Override copy() in data classes • Not inner classes in enum entries • Passing a single item for a vararg parameter in the named form • Inner classes of generic classes extending Throwable
  • 43. Other • Support for ::foo as a shorthand for this::foo • JS TypedArrays support for Kotlin primitive array (IntArray, FloatArray, etc) enabled by default • The Kotlin compiler now provides an option to treat all warnings as errors • Support in Kotlin Native 0.4
  • 44. Compilation Performance Approximately 25% improvement over Kotlin 1.1
  • 47. expect & actual // expected platform-specific API expect fun hello(world: String) Common // actual JVM implementation actual fun hello(world: String) = println(“Hello, $world, on the JVM!") JVM // actual JS implementation actual fun hello(world: String) = console.log("Hello, $world, on the JS!") JS
  • 48. expect class Date() { fun getDate(): Int fun getMonth(): Int } Common actual class Date { private val calendar: Calendar actual constructor() { calendar = Calendar.getInstance() } actual fun getDate() = calendar[DAY_OF_MONTH] actual fun getMonth() = calendar[MONTH] } JVM actual external class Date { actual fun getDate(): Int actual fun getMonth(): Int } JS
  • 51. //common-jvm/build.gradle apply plugin:'kotlin-platform-jvm' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" expectedBy project(":common") } JVM //android/build.gradle apply plugin: 'kotlin-android' dependencies { implementation project(":common-jvm") } Android //common/build.gradle apply plugin: 'kotlin-platform-common' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" } Common
  • 52. Common modules • Test
 Run test both on Java & JS platforms • Serialization
 Marshal Kotlin objects between different tiers of your application, based on JSON or ProtoBuf as serialization format • HTML
 The same code to render HTML in the backend and in the frontend
  • 53. Future commons • IO • Networking (HTTP, TCP, etc.) • Dates
  • 55. Summary • Allow to write parts of app in same language
  • 56. Summary • Allow to write parts of app in same language • Interoperability on supported platforms
  • 57. Summary • Allow to write parts of app in same language • Interoperability on supported platforms • Shared business logic
  • 58. Summary • Allow to write parts of app in same language • Interoperability on supported platforms • Shared business logic • UI is platform-specific
  • 59. Summary • Allow to write parts of app in same language • Interoperability on supported platforms • Shared business logic • UI is platform-specific • JVM/JS code reuse already worked, Native coming soon
  • 60. Summary • Allow to write parts of app in same language • Interoperability on supported platforms • Shared business logic • UI is platform-specific • JVM/JS code reuse already worked, Native coming soon • Support of Multiplatform projects in IDEA 2017.3