Kotlin 1.2: generic code for JVM and JavaScript
Yesterday, JetBrains released the Kotlin 1.2 release. The new version is a big step towards making Kotlin the most convenient tool for developing all the components of a modern application.
In version Kotlin 1.1, we officially released JavaScript support - the ability to translate Kotlin code into JS and execute it in a browser. In this version, we add to this the ability to reuse code between the JVM and JavaScript . Now you can use the same implementation of business logic in all components of your application - the backend, the frontend in the browser and the mobile application for Android. We are also working on libraries that help with this - in particular, on a cross-platform library for serialization.
Kotlin 1.2 is available out of the box in IntelliJ IDEA 2017.3 , which is also coming out this week. If you are using Android Studio or an older version of IntelliJ IDEA, you can upgrade using the Tools | Kotlin | Configure Kotlin Plugin Updates.
Our external contributors made a great contribution to this release, and we would like to thank everyone who sent us feedback and bug reports, and especially those who sent us pull requests.
Multi-platform projects
Multi-platform projects allow you to assemble all the components of your application - backend, frontend and Android application - from a common code base. Such a project consists of general modules that contain platform-independent code, as well as platform-specific modules that contain code for a specific platform (JVM or JS) and can use the libraries of this platform. In order to call platform-specific code from a common module, you can specify expected declarations — declarations for which all platform-specific modules must provide actual implementations .
More information on using multi-platform projects can be found in the documentation .
As already mentioned, we are also working on libraries that help port code to common modules:
- kotlin.test , which is included with Kotlin 1.2, allows you to run the same test classes under JVM and JS;
- kotlinx.html supports isomorphic rendering - using the same code to generate HTML on the backend and in the browser;
- kotlinx.serialization allows you to easily transfer Kotlin objects between different layers of your application, using JSON or Protobuf as serialization formats.
Please note that support for multi-platform projects is released in experimental status. This means that you can write such projects now, but in the future we may need to change its design (if this happens, we will provide tools for migrating existing code).
Compilation performance
While working on version 1.2, we put a lot of effort into making compilation faster. We have already achieved an acceleration of about 25% compared to version 1.1, and we see great potential for further optimizations, which we plan to release in updates 1.2.x.
The graph shows the difference in compilation time between two large projects in JetBrains using Kotlin:
Other language and library improvements
The new version also includes less significant improvements in the language and standard library:
- Compact syntax for passing multiple arguments to annotation (literals for arrays);
- Modifier support
lateinit
for top-level properties and local variables, as well as checking whether the--lateinit
property has been initialized; - Smarter smart castes and improved type inference in some cases;
- Compatibility of the standard library with restrictions on splitting packages between jar files introduced in Java 9;
- New package
kotlin.math
in the standard library; - New features in the standard library for working with sequences and collections, including a set of functions for splitting a collection or sequence into (possibly overlapping) groups of a fixed size.
More complete information about changes in the language and the standard library can be found in the document What's new in Kotlin 1.2 .
Kotlin Worldwide
Since the release of Kotlin 1.1 in March this year, the distribution of its use around the world has greatly expanded. The culmination was KotlinConf , our first conference we held in San Francisco on November 2-3 and attended by about 1,200 of our users. You can see the records of all reports on the conference website .
Kotlin has also become an officially supported development language for Android. The Kotlin plugin has been bundled with Android Studio since version 3.0, and on the Android site you can find official examples and a style guide . Already, Kotlin uses more than 17% of projects in Android Studio , including many applications of both the brightest startups and Fortune 500 companies.
On the server side, Spring Framework 5.0 was released with a lot of features for Kotlin support , and vert.x officially supports Kotlin since 3.4.0. In addition, support for build scripts on Kotlin is already included with Gradle, and the Gradle Kotlin DSL project is already close to release 1.0.
The number of lines of code in open-source repositories on GitHub has exceeded 25 million. And on Stack Overflow, Kotlin is also one of the fastest growing and least favorite languages .
The growth of communities around Kotlin is also impressive. There are more than 100 groups of Kotlin users all over the world, and there are so many reports about Kotlin that we can hardly manage to track them all - but for those we know about, the map gives a good idea of how widespread the use of Kotlin is.
For those who are just starting to use Kotlin, more and more books are available (including our own “Kotlin in Action” , which has already been translated into Russian , Japanese , Chinese and Portuguese ), online courses, tutorials and other resources .
Chat with the team: webinar and Ask Me Anything on reddit
To tell you more about the new release, we will conduct a webinar on the development of multi-platform projects using Kotlin 1.2 on December 7, at 8 pm Moscow time. Do not forget to register; the number of participants is limited!
In addition, our team will hold an AMA (Ask Me Anything, Open Interview) at Kotlin Reddit on December 5th. We will start at 2 pm Moscow time and will answer your questions within 24 hours.
How to upgrade
As always, you can try Kotlin right in your browser, at try.kotlinlang.org
- In Maven, Gradle, and npm : Specify version number 1.2.0 for the compiler and standard library
- IntelliJ IDEA: Version 2017.3 already includes a new plugin; in older versions, update the plugin to version 1.2
- In Android Studio: Install the plugin from the Settings | Plugins or upgrade through Tools | Kotlin | Configure Kotlin Plugin Updates
- The command line compiler can be downloaded from the release page on GitHub .
Compatibility: In Kotlin 1.2, the language and the standard library are backward compatible (modulo bugs) : the code that compiled and worked in versions 1.0 and 1.1 will also work in version 1.2. In order for large teams to be able to upgrade to a new version gradually, we added a compiler option that disables the ability to use new features of the language and library. Information on possible difficulties can be found in the documentation .
Have a nice Kotlin!