Now we are very proud to release Kotlin 1.3-RC, which will be the last preview release before 1.3. This release fixes most of the key bugs related to the new features, but there are a few other updates worth mentioning:

  • The API of Ktor has been improved, and we look forward to your experience and feedback. Ktor is a coroutine based framework that allows you to elegantly build Web applications, Http services, mobile applications, and Web pages.
  • All new projects have adopted official code specifications, and we strongly encourage you to do the same.
  • Program entrancemainThe suspend function can take the form of a no-argument function. It can also be a suspend function.
  • Scripting support introduced in 1.2.50 has also been updated and improved.
  •  kotlinx.serializationThe plugins have been incorporated into the Kotlin main project and are integrated into the compiler plug-in.
  • We deprecated some of the standard library apis, of course, for those that were deprecated in the past we will report an error.
  •  org.jetbrains.annotationsThe annotations are separate from the standard library and become a new component that developers can rely on freely.

Thanks to contributors from the community, this release incorporates the following code submissions from developers: Toshiaki Kameyama, Cuihtlauac ALVARADO, kenji tomita, Martin Petrov, Denis Vnukov, shiraji, Paul de Vrieze, Raluca Sauciuc, Ivan Gavrilovic.

For full updates, see Update Log.

If you have any problems trying out the new features and features in version 1.3, please do not hesitate to contact us. We look forward to and appreciate your feedback. The final version of Kotlin 1.3.0 is coming soon, so please share your experience.

2018 Kotlin Developer Conference

The Kotlin Developer Conference is coming soon! For developers who are not able to attend the conference, we will provide live broadcast and material sharing. Please register to receive our live notification.

It’s time to migrate your coroutine code

Starting with Kotlin 1.3, the coroutine will enter a stable state. With this in mind, you will be able to migrate your coroutine code as soon as 1.3.0 is released, and we will provide tools to help you do so.

For Kotlinx. coroutines:

  1. You need to update to the latest experimental version, which is currently 0.26.1 (there may be minor updates before Kotlin 1.3 is released)
  2. Switch your project directly to Kotlin 1.3, and the IDE’s tools will help you with the migration, currently to 0.26.1-EAP13, which is built on Kotlin 1.3. This migration is mainly to replace experimental in the package name.
  3. After Kotlin 1.3 is officially released,kotlinx.coroutinesThere will also be a 1.0 release, where you just need to update the version number and recompile the code.

Note that Kotlinx.Coroutines 1.0 will discard all deprecated interfaces and declarations from previous versions of 0.x and will not be binary compatible with 0.x-EAP13, so you will need to clean up your code that uses outdated apis before switching to the official version.

Kotlinx. coroutines will also have some apis that are marked “Unstable” and will be fixed in future updates. Although using these “unstable” apis requires specific configuration options, the core apis will be finalized in 1.0 and guaranteed to be backward-compatible with subsequent updates, just like the Kotlin library.

A “Main” function that takes no arguments

Like many other languages, since 1.3 we’ve allowed the “main” function to take an optional array of strings, so that the classic “Hello, World! In Kotlin it’s even shorter:

fun main() {
    println("Hello, World!")
}
Copy the code

The suspended “main” function

In other words, you no longer need to use “runBlocking” to call other “suspend” functions directly from “main” :

import kotlinx.coroutines.* //sampleStart suspend fun main() = coroutineScope { val task1 = async { fetchResult(id = 42)  } val task2 = async { fetchResult(id = 99) } val results = awaitAll(task1, task2) log(results) } //sampleEnd suspend fun fetchResult(id: Int): String { log("started request #$id") delay(500) return "result #$id" } val startedAt = System.currentTimeMillis() fun elapsed() = System.currentTimeMillis() - startedAt fun log(message: Any) = println("At ${elapsed()} ms: $message")Copy the code

Ktor framework

The collaboration has finally “graduated” so mom doesn’t have to worry about us releasing our own asynchronous framework anymore. We did a lot of work on this, most notably Ktor, an asynchronous framework for connecting applications. It includes a cross-platform HTTP client and a JVM-based HTTP server.

The client currently supports JVM/Android and iOS, and will support more platforms including JS (browser) and various native platforms in the future. The server side runs on top of the JVM, and you can use Netty, Jetty, and other Servlet-containers similar to Tomcat.

Ktor is well tested, easy to use, and performs well. See ktor. IO /. Its 0.9.5-RC13 is compatible with Kotlin 1.3-RC and 0.9.5 is compatible with Kotlin 1.2.70.

Work with us to build our own asynchronous framework so we can make our code readable and maintainable by leaps and bounds!

Coding standards

The official code specification document has been around for some time now, and it’s time for further work: starting with Kotlin 1.3, all new projects created using IntelliJ IDEA will apply this code specification.

Although we recommend sharing codeStyles by submitting.idea/codeStyles to VCS, many developers are reluctant to do so. So we introduced a Gradle property, kotlin.code.style, which can be set to official or obsolete. As a result, other ides can also enjoy this feature.

If you want to use the old code style, just set kotlin.code.style=obsolete to avoid migration trouble later. This property also works in Maven.

The script

There have been a number of improvements to script support in this release, the most important of which is a new, cleaner API. While the features supported by scripts may need to be experimented with for a while, for now it looks like the API is pretty much in place. Some of these useless and unimplemented apis were removed, and we intend to recall most of them in future releases when the time is right.

To simplify script project building and tool script dependency, we provide a new component, Kotlin-main-kts. This simple JAR package provides some script definitions and a basic Maven build parser so that we can write the following scripts:

@ file: Repository (" https://jcenter.bintray.com ") @ file: DependsOn (" org. Jetbrains. Kotlinx: kotlinx - HTML - the JVM: 0.6.11 ") import kotlinx.html.* import kotlinx.html.stream.* print(createHTML().html { body { h1 { +"Hello, World!" }}})Copy the code

The runtime simply adds kotlin-main-kts.jar to the classpath:

kotlinc -cp <path/to/kotlin-main-kts.jar> -script sample.main.kts

There are many other fixes and enhancements to script support. We recommend you to try more cases and give positive feedback

The complete Kotlin script proposal and its current implementation status can be found in Keep-75.

Serialization plug-in for experimental state

Starting with this release, the previously separate plug-in kotlinx.serialization will be incorporated into Kotlin’s compiler plug-in.

Although it will remain experimental in Kotlin 1.3, it will not affect its use in production environments, it is mature and stable enough, and we look forward to your feedback. Please refer to keep-149 for relevant proposals. If you have any comments or suggestions, please open an issue for discussion.

Inline classes Inline classes

We tweaked the binary representation of the inline class to make it more compact and current, as well as fixing some key issues. Kotlin reflection can also handle inline classes correctly and perform automatic unpacking and boxing.

The standard library

This version, by contrast, focuses more on pre-release code cleaning than new features.

Nullable hashCode()

When implementing a generic container class, we usually need to get the hash value of the element, which can also be null, so in the past we needed to use? . And the Elvis operator to solve the problem:

element? .hashCode() ? : 0.

And now we have Any? .hashcode (), for any element whether empty or not: element.hashcode ().

Empty checking of elements during Range iteration

When value is nullable and Range is Iterable and large, value in from.. A null check in to would be time-consuming. In this case, the inclusion of the range is reduced to Iterable

. Contains (T), so that the entire process is Iterable traversal (until the element is found or determined not to be found).

To solve this problem, we introduce a series of contains overloads, starting with IntRange. Contains (Element: Int?). For example, it checks whether the element argument is empty and then performs a quick inclusion judgment:

class IntRange(start: Int, endInclusive: Int) : IntProgression(start, endInclusive, 1), ClosedRange<Int> { ... Override fun contains(value: Int): Boolean = first ≤ value && value ≤ last... } @sincekotlin ("1.3") public inline operator fun IntRange. Contains (element: Int?) : Boolean { return element ! = null && contains(element) }Copy the code

SuccessOrFailure is renamed Result

We provided a SuccessOrFailure class that encapsulated the results of the Kotlin function in the previous Kotlin 1.3 preview, which was renamed Result after review and community feedback. This class is currently used primarily for coroutines, as an argument to continuation. resumeWith. There are a number of design cues in Kotlin that can be used to extend error handling in the future, which will require us to redesign the semantics of code that uses this Result class as a return type. Therefore, to prevent future designs from breaking such code, the Kotlin 1.3 compiler will report errors for such declarations, with the exception of library functions that operate specifically on the Result type. For details, see KEEP-127.

Create functions for Sequence and iterator and their Scope classes

Before the coroutine API is finalized, we need to rename buildSequence and buildIterator. These names are mostly in keeping with buildString and some of the function proposals for building collection framework types. However, we have recently realized that the sequence and string creation functions are quite different in terms of lazy loading, and the so-called consistency is actually not very reasonable.

These build functions are renamed from buildSequence {} and buildIterator {} to Sequence {} and iterator {}. The Receiver class for the parameter is changed from SequenceBuilder to SequenceScope.

The Sequence creation code would then be:

import kotlinx.coroutines.* //sampleStart fun idCandidates(baseId: String): Sequence<String> = sequence { yield(baseId) for (suffix in 'a'.. 'z') { yield(baseId + "-" + suffix) } } //sampleEnd fun main() { idCandidates("base-id").take(10).forEach(::println) }Copy the code

When a signed integer goes to an unsigned integer, the sign bit expands to a long integer

Int.toulong () and other similar functions extend the sign bit to the high level instead of 0. So (-1).toulong () is now equal to ulong.max_value (0xFFFF_FFFF_FFFF) instead of uin.max_value (0x0000_0000_FFFF_FFFF).

Annotations become independent artifacts

Release the standard library is no longer with the compiler contains org. Jetbrains. Annotations in the annotations, this can also be consistent with the standard issued by the Maven Central library. These annotations can now be found in annotations-13.0.jar and mutability- Annotations -compat.jar.

Discards a mixture of integer and floating-point interval inclusion operators

As mentioned earlier, there are problems with nullable inclusion, but the other problem is that integer ranges encounter floating-point arguments and the like. For example 3.14 in 1.. 3 can compile and run, but the result is a bit awkward: true. We have discarded such Contains operator overloads and will remove them gradually.

Other abandonment notices

For apis that have been deprecated in the past, we will raise the deprecation level and report errors instead of warnings for code that uses these apis.

The JS standard library has been deprecated by the API.

  • jsClassfunction
  • kotlin.Synchronized 和 Volatileannotations
  • kotlin.js.Mathfunction
  • kotlin-test-jsamongorg.junit.Testannotations

If you are not familiar with these, that’s ok. Otherwise, follow the instructions to migrate your code as soon as possible.

In the next version is 1.4, we’re going to remove the standard library of jQuery type of statement, the corresponding function will be provided by https://bintray.com/kotlin/js-externals/kotlin-js-jquery.

Command line compiler

This version allows us to choose another way to pass arguments to the compiler through files. In addition to using -xargFile =filename. TXT introduced in 1.2.50, you can also pass arguments like @filename. TXT directly to Kotlinc, and the contents of the file will be parsed as arguments line by line. This will make it easier to compile large numbers of source files using Kotlinc, as well as to handle longer and more complex file paths.

Another experimental feature to graduate from this release is the progressive compilation mode introduced in 1.2.50, which can be turned on by -progressive.

How to try

In the Maven project/Gradle: add the repository to build scripts and projects rely on https://dl.bintray.com/kotlin/kotlin-eap. Use 1.3.0-RC-57 as the compiler and library version number.

In IntelliJ IDEA: In Tools → Kotlin → Configure Kotlin Plugin Updates, select “Early Access Preview 1.3” in the Update channel and click Check for Updates.

The command line compiler is available for download on the Github Release page.

At try.kotlinlang.org: Select 1.3‑RC for the compiler from the drop-down list in the lower right corner.

Kotlin 1.3 RC is Here: Migrate Your Coroutines!