Kotlin 1.1.4 released

New update for officially supported programming language for Android available now
15 August 2017   638

Good news for Kotlin fans. Version 1.1.4 is out now.

What's inside?

This update:

  • Fixes a major performance regression in the IntelliJ IDEA plugin
  • Adds support for package-default nullability annotations
    Starting with this release, Kotlin supports package-default nullability annotations (such as JSR-305’s @ParametersAreNonnullByDefault and the @NonNullApi annotation introduced in Spring Framework 5.0).
     
  • Improved Java 9 support
    Now Kotlin performs module-based visibility checks based on information from module-info.java. Running the compiler under JDK 9 is now also supported.
     
  • Adds initial, experimental support for generating Android Parcelable implementations using the @Parcelize annotation
    Android Extensions plugin now supports not only Activities and Fragments, but also custom Views and even custom layout containers such as a ViewHolder. Also, variants are now fully supported.
     
  • Adds a tool for JavaScript dead code elimination, improves sourcemap support for JS debugging and JS unit testing support
    Kotlin 1.1.4 adds a new tool to eliminate dead code from the .js files produced by the Kotlin/JS compiler. 
     
  • Generates more efficient bytecode
    Exceptions from named suspending functions now originate from the function itself, which makes their stack-tracer easier to read, and the bytecode performs better in many cases.
     
  • Adds many new features to the IntelliJ IDEA plugin

All changes available at changeslist

How to convert list to map in Kotlin

Two ways to convert list to map in Kotlin, with code examples
31 October 2017   504

For example, you have a list of strings like:

val list = listOf("a", "b", "c", "d")

and you need to convert it to a map, where the strings are the keys.

There are two ways to do this:

The first and most performant is to use associateBy function that takes two lambdas for generating the key and value, and inlines the creation of the map:

val map = friends.associateBy({it.facebookId}, {it.points})

The second, less performant, is to use the standard map function to create a list of Pair which can be used by toMap to generate the final map:

val map = friends.map { it.facebookId to it.points }.toMap()