Kotlin is an open-source, general-purpose, free, statically typed “realistic” programming language created for the JVM (Java Virtual Machine) and Android that combines functional programming and object-oriented and features.
Kotlin is focused on security, interoperability, accuracy, and tooling support.
Kotlin seems more like a streamlined and compact variant of Java. It is designed to eliminate many common errors like the risk of null pointer references moreover it also helps streamline the handling of null values.
The average time required for a Java developer to learn Kotlin is only a few hours which is a small price to pay for reducing null reference errors, allowing extension functions, promoting functional programming, and adding coroutines.
This typical rough calculation shows that approximately that there is a 40 percent reduction in the number of lines of code from Java to Kotlin.
Kotlin was originated at JetBrains. JetBrains has now made available Kotlin 1.5.0-RC, a release for the next version of its open-source programming language designed for compatibility with the Java ecosystem.
Kotlin 1.5.0-RC, this new release incorporates all the new features outlined for version 1.5.0. It includes new language features, stdlib updates, and also an improved testing library.
Some of the major changes highlighted are that the operations and unsigned integer types are now classified as stable.
As they had earlier been a beta characteristic since Kotlin 1.3, but progression to stable means that it is now reliable and safe for developers to utilize them in any production projects.
These new stable APIs are unsigned integer ranges, types, and progressions of unsigned integer types, plus functions that work with unsigned integer types.
Another big change is that Kotlin now introduces a new way to utilize advanced non-blocking Java IO in a Kotlin-idiomatic style through the extension functions for java.nio.file.Path.
This ability was introduced as an experimental feature in Kotlin n1.4.20 but is presently available without requiring an opt-in, while the current extensions for File API continue to be available.
There are furthermore updates added to the Kotlin test library, combining new features for developers such as a single kotlin-test dependency in multiplatform projects.
The Kotlin team announced that the only changes between this and the release before this would be the fixes so that developers can be assured of feature stability at this point.
Modern language features, stdlib updates, an enhanced testing library, and several more changes are getting a final polish.
Now let us understand the changes made to the Kotlin standard and test libraries in 1.5.0-RC:
1) Stable Unsigned Integer Types
This standard library incorporates the unsigned integer API that is beneficial for dealing with non-negative integer operations.
It incorporates Unsigned number types: ULong, UInt, UShort, UByte, etc. Aggregate types: ranges, arrays, and progressions of unsigned integers: UIntRange, UIntArray, and related containers. The new stable APIs are:
- Progressions and Ranges and of unsigned integer types
- Unsigned integer types
- Functions that work with unsigned integer types
Also, Read – Google Cloud vs AWS vs Azure – Choose the Right Cloud Platform
2) Locale-Agnostic API for Lowercase and Uppercase
As everyone would be familiar with the stdlib functions for adjusting the case of characters and strings: toLowerCase(), toUpperCase(), toTitleCase().
They are locale-sensitive, which means their result can vary depending on the locale.
Now there is a new locale-agnostic API for modifying the case of characters and strings: uppercase(), lowercase(), titlecase() extensions, etc.
These new functions work the same way despite the platform locale settings.
3) Extensions for java.nio.file.Path API
This new version of Kotlin provides a method to utilize the modern non-blocking Java IO in a Kotlin-idiomatic style out of the box through the extension functions for java.nio.file.Path.
4) Extended Multiplatform Char API
We continue to extend the multiplatform portion of the regular library to provide all of its abilities to the multiplatform project standard code.
Now, several Char functions are available on all platforms:
Char.isLetter(), Char.isDigit(), Char.isLetterOrDigit(), Char.isUpperCase(), Char.isLowerCase(), Char.isTitleCase()
5) Strict versions of String?.toBoolean()
Kotlin’s String?.toBoolean() function is extensively used for building boolean values from strings. It runs pretty easily: it’s true on a string “true” despite its case and false on every other string, including null.
New case-sensitive strict versions of the String?.toBoolean() is here to avoid such errors:
String.toBooleanStrictOrNull() returns null for all inputs except literals “false” and “true”. String.toBooleanStrict() throws an exception for all inputs except literals “true” and “false”.
6) Clear Char-to-digit and Char-to-code Conversions
The process for producing a UTF-16 code of a character – the toInt() function – was a common trap as it looked quite similar to String.toInt() on one-digit strings that returns an Int presented by this digit.
"4".toInt() // returns 4
To resolve these problems, now there is a set of new functions for conversion between characters and their integer codes including numeric values:
- Char(code) and Char.code for converting between a char and its code.
- digitToInt(radix: Int)
- digitToChar(radix: Int) produces a char from a digit
These functions make the code more readable.
7) Math Operations: The Mod Operator and Floored Division
In Kotlin, the division operator (/) on integers describes the trimmed division, which leaves the fractional part of the result.
In modular arithmetics, there is also an option – floored division that rounds the result down, which gives a different result on negative numbers. Under 1.5.0-RC, we present the floorDiv() function that performs floored division on integers.
8) Collections: firstNotNullOfOrNull() and firstNotNullOf()
Kotlin collections API includes different popular operations on collections with built-in functions.
For events that aren’t common, you normally combine calls of these functions.
But now in 1.5.0, you can do this in a single call of a new function firstNotNullOf(). Together with firstNotNullOf(), there is an added *orNull() counterpart that produces null if there is no value to return.
9) Test Library Changes
With 1.5.0-RC, you can try several new features like:
- Automatic option of a testing framework for JVM/Kotlin source sets.
- Single kotlin-test dependency in multiplatform projects.
- Assertion function updates.
10) kotlin-test Dependency in Multiplatform Projects
Under 1.5.0, it has become easier to set up a dependency on the kotlin-test for all source sets.
- kotlin-test-js for Kotlin/JS source sets.
- kotlin-test-junit for JVM source sets.
- kotlin-test-common and kotlin-test-annotations-common for common source sets.
- No extra artifact for Native/Kotlin source sets as Native/Kotlin presents built-in implementations of the kotlin-test API.
11) Automatic Choice of a Testing Framework for Kotlin/JVM Source Sets
Now as you define the kotlin-test dependency in the common test source set, the JVM source sets automatically to get the dependency on JUnit 4. You can write and run tests instantly!
12) Assertion Functions Updates
There are several new assertion functions for 1.5.0, including improvements to existing ones.
These are the added new functions:
- assertIs<T>() and assertIsNot<T>() check the value’s type
- assertContentEquals() matches the container content for arrays, series, and any Iterable. More specifically, it examines whether expected and actually hold the same elements in the same order.
- assertNotEquals() and assertEquals() for Float and Double have new overloads with a third parameter i.e. precision
- assertContains() examines the presence of an item in an object with the contains() operator-defined: list, array, range, and so on.
Also, Read – NativeScript 8.0 Released With Apple M1, Webpack 5 Support
Final Verdict
Get all these modern Kotlin APIs to your real-life projects with 1.5.0-RC! In Android Studio, install the Kotlin plugin 1.5.0-RC.
Discover how to get the EAP plugin versions and create your existing projects with 1.5.0-RC to explore how they will work with 1.5.0.
With this latest simplified configuration for research releases, you simply need to change the Kotlin version to 1.5.0-RC and change the dependency versions, if required. Install 1.5.0-RC, as always, you can examine the most advanced version online within the Kotlin Playground.
This is the ultimate opportunity for you to influence the next feature release!