In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains what are the new features of Kotlin 1.4. the content of the explanation is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought to study and learn what are the new features of Kotlin 1.4.What are the new features of Kotlin 1.4?
New language features
The new language features introduced in Kotlin 1.4 improve the "ergonomics" of writing Kotlin code, such as:
SAM conversion of Kotlin Interface
In the past, only functional interfaces defined in the Java programming language (that is, a single abstract method-SAM) benefited from the shorthand syntax in Kotlin:
Executor.execute {println ("This is shorthand for passing in a Runnable")}
Kotlin 1.4 can now mark Kotlin interfaces as functional interfaces and make them work in a similar manner by adding the fun keyword:
Fun interface Transformer {fun transform (x: t): U} val length = Transformer {x: String-> x.length}
The Kotlin 1.4 release notes page provides more information about the new language features, such as mixing naming and positional parameters, trailing commas, callable reference improvements, and the use of break and continue within when in a loop.
Release Notes https://kotlinlang.org/docs/reference/whatsnew14.html#mixing-named-and-positional-arguments
Explicit API mode
Another new feature is the explicit API schema, which is targeted at Kotlin library authors.
This mode enforces certain language properties of the Kotlin, which are usually optional, such as specifying visibility modifiers, as well as explicit typing of any public declaration, to prevent errors in designing the public API of the library. The official documentation explains how to enable explicit API mode and start using these additional checks.
Official documentation: explicit API schema https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors
Improvement of Compiler
The above language features are part of the changes that closely fit developers in Kotlin 1.4. most of the other work is focused on improving the overall quality and performance of the Kotlin compiler.
Now, one of the advantages that all developers can take advantage of is the more powerful new type inference algorithm (enabled by default), which automatically infers types in more use cases and supports intelligent transformations even in complex scenarios. Help developers improve their productivity.
In addition to the type inference algorithm, Kotlin 1.4 also brings a new compiler backend (Alpha stabilization phase, optional) for Kotlin/JVM and Kotlin/JS, which generates code with the IR compiler and uses it for the Kotlin/Native backend.
Jetpack Compose requires a Kotlin/JVM IR backend. Google engineers are working with JetBrains to make it the default JVM compiler backend.
Therefore, even if you are not currently using Jetpack Compose for development, we also recommend that you try the new alpha version of the Kotlin/JVM backend and submit it to the issue tracker if you have any questions or functional requests in use.
Problem tracker http://kotl.in/issue
Specify additional compiler options in the Gradle build script to enable the new JVM IR backend:
KotlinOptions.useIR = true
Experience Kotlin 1.4 now!
There are two steps to update the project and IDE to Kotlin 1.4.
First, make sure you use the latest version of Android Studio to maximize performance benefits and compatibility with the latest Kotlin plug-ins. When the Kotlin 1.4.0 plug-in compatible with the IDE version is available, Android Studio will prompt you, or you can go to Preferences | Plugins to manually trigger the update.
Android Studio https://developer.android.google.cn/studio
After you enable the plug-in, you can update the version of the Kotlin Gradle plug-in in the build.gradle script to upgrade the application project to use Kotlin 1.4. Depending on how the plug-in is managed, you must update the version in the buildscript block of the top-level project:
Buildscript {
Dependencies {
Classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0"
}
}
Or change the version number in the plugins block of the module-level build.gradle file:
Plugins {id' org.jetbrains.kotlin.android' version '1.4.0'} Thank you for your reading, these are the contents of "what are the new features of Kotlin 1.4". After the study of this article, I believe you have a deeper understanding of what the new features of Kotlin 1.4 have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.