Discover what's new in Kotlin 1.2: syntax, standard library, performance and , of course, "Multiplatform project". Take closer look at how Kotlin authors see way of reusing code between platforms.
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
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 }
}
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
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
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
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
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