今天Kotlin 1.3正式发布:支持协程和多平台组件

简介: image今天,Kotlin 官方博客正式发布了 Kotlin 1.3,还附带了一些开源库、构建工具和学习资源。在这次更新中,协程(Coroutines)特性已经稳定,它使得非阻塞代码易于读写,Kotlin 1.3 还带来了 Kotlin / Native Beta,它可将 Kotlin 代码直接编译为本机二进制文件,此外,Kotlin 的跨平台功能将为 Android 和 iOS 应用程序等组件之间共享业务逻辑,服务器也可以与 Web 和移动客户端共享逻辑,而且多平台库让日常的开发变得便捷。
img_76c20579d3b2b45169a7ea143d1719be.jpe
image

今天,Kotlin 官方博客正式发布了 Kotlin 1.3,还附带了一些开源库、构建工具和学习资源。

在这次更新中,协程(Coroutines)特性已经稳定,它使得非阻塞代码易于读写,Kotlin 1.3 还带来了 Kotlin / Native Beta,它可将 Kotlin 代码直接编译为本机二进制文件,此外,Kotlin 的跨平台功能将为 Android 和 iOS 应用程序等组件之间共享业务逻辑,服务器也可以与 Web 和移动客户端共享逻辑,而且多平台库让日常的开发变得便捷。

Kotlin 的生态现状

今年以来,Kotlin 的使用率有了很大的增长,自今年 1 月份以来,约有 150 万开发者使用了 Kolin 编程,是去年同期的两倍,来自 Stack Overflow 的一项问卷调查显示,超过 10 万名受调者表示 Kotlin 是他们的第二大编程语言。

目前,Kotlin 开源社区创建了很多优秀的库,如 RxKotlin、mockito-kotlin、TornadoFX、Kodein 和ΛRROW。而诸如 Square’s Okio 和 LibreOffice 这样的项目已经开始逐渐迁移到 Kotlin 上来,这些预示着 Kotlin 生态系统正逐渐走向成熟。

详解 Kotlin 1.3 新功能

Coroutines 已经稳定

Coroutines 是 Kotlin 1.1 引入新的异步 API,它是一个强大的工具,之前该特性一直处于试验阶段,而在最新的 v1.3 中,Coroutines 语法和标准库 API 都已稳定,你可以开始使用它了。

详情请阅读:https://kotl.in/coroutines

Kotlin / Native Beta

Kotlin / Native 使用 LLVM 将 Kotlin 源代码编译为独立的二进制文件(无需 VM),它适用于各种操作系统和 CPU 架构,包括 iOS、Linux、Windows、Mac 甚至 WebAssembly 和嵌入式系统(如 STM32),它具有全自动内存管理功能,支持与 C、Objective-C(和 Swift)互操作。

详情请阅读:https://kotlinlang.org/docs/reference/native-overview.html

多平台项目和工具

Kotlin 团队称,能在所有平台上运行是 Kotlin 的目标,但达成这个目标的前提是,得先在多平台间实现代码共享,通过支持 JVM、Android、JavaScript 和 Native,Kotlin 现在已经可以处理现代应用程序的任何组件。虽然 Kotlin 的多平台功能仍处于试验阶段,但 1.3 版本算是向前迈出了一大步。

Kotlin 1.3 还附带了一组多平台库,涵盖了 HTTP、序列化和协同管理等日常任务。编写多平台代码最简单的方法是依赖这些库,你还可以创建自己的多平台库,将特定平台的依赖项包装到通用 API 中。

详情请阅读:https://kotlinlang.org/docs/reference/multiplatform.html

其他特性

•    支持内联类( inline classes)
•    支持无符号整型
•    支持 Kotlin/JS 增量编译
•    标准库支持扩展到 Kotlin / Native等

What’s new in Kotlin 1.3

Kotlin 1.3’s contracts are an experimental addition meant to enrich the type information available through the function system with additional meanings useful at the call site. A contract lets a function tell the compiler things such as “I affect smart casts this way” or “I execute this lambda exactly once.” The Kotlin standard library already has contracts added to several functions, which work regardless of experimental flags.

Other new features in Kotlin 1.3 include:

  • The coroutines capability is in stable status, meaning there have been changes in the APIs and ABIs based on feedback. There is migration support to bridge old, experimental coroutines with new ones. Also, introspection is supported for suspend functions: isSuspend, KCallable.callSuspend, and KCallable.callSuspendby.

  • In the standard library, support has been improved for unsigned integer types. Unsigned types and arrays should feel more like first-class citizens.

  • With an API improvement in the standard library, the Random class introduced in the previous beta has gained extensions to generate unsigned numbers and arrays and unsigned bytes. Also, an extension called random() is being introduced for collections, arrays, and ranges to obtain a random element from elements of that collection, array, or range.

  • An API has been added to kotlin-reflect that can enumerate direct subtypes of a sealed class, namely sealedsubclasses.

  • Automatic mangling is being introduced for names of functions that use inline classes in their signatures. This prevents platform signature crashes when there are several overloads that are different just in the inline type but not in the carrier type. Mangling also forbids accidental use from Java, which may be undesirable because inline classes are a purely Kotlin concept.

  • Support for older source language versions is being deprecated, through the -language-version- flag with values 1.0 and 1.1 for kotlinc-1.3 and above. This change only affects compilation of source code for old target versions.

  • Code can be compiled to native binaries, via a beta of Kotlin/Native. Kotlin/Native uses LLVM compiler technology to compile Kotlin sources to standalone binaries for iOS, Linux, Windows, MacOS, and WebAssembly.

  • Multiplatform capabilities let business logic be shared among components on supported platforms, such as Android and iOS.

  • Kotlin 1.3 Tools for Kotlin/Native and multiplatform projects, available in the community and ultimate editions of the JetBrains IntelliJ Idea IDE, as well as in the Android Studio IDE. For Android Studio, use Plugin Manager to upgrade to Kotlin 1.3.

  • A sequence debugger to visualize lazy computations.

  • Experimental support for unsigned integers, which can assist with byte manipulation and other low-level code.

  • Experimental support for inline classes, for performance and type safety.

Kotlin 1.3 released with stable coroutines, multiplatform projects and more

In the Kotlin 1.3 release, coroutines are now stable, scalability is better, and Kotlin/Native Beta is added.

Coroutines are stable in Kotlin 1.3

Coroutines provide a way to write non-blocking asynchronous code that’s easy to understand. It is a useful tool for activities ranging from offloading work onto background workers to implementing complicated network protocols. The kotlinx.coroutines library hits is at 1.0. It provides a solid foundation for managing asynchronous jobs various scales including composition, cancelation, exception handling and UI-specific use cases.

Kotlin/Native Beta

Kotlin/Native makes use of LLVM to compile Kotlin sources into standalone binaries without any VM required. Various operating systems and CPU architectures including iOS, Linux, Windows, and Mac are supported. The support extends to even WebAssembly and embedded systems like STM32. Kotlin/Native has a fully automatic memory management and can interoperate with C, Objective-C, and Swift. It exposes platform APIs like Core Foundation, POSIX, and any other native library of choice.

The Kotlin/Native runtime promotes immutable data and blocks any attempts of sharing unprotected mutable state between threads. Threads don’t exist for Kotlin/Native, they are abstracted away as a low-level implementation. Threads are replaced by workers which are a safe and manageable way of achieving concurrency.

Multiplatform projects in Kotlin 1.3

Kotlin supports JVM, Android, JavaScript, and Native. Hence code can be reused. This saves effort and time which can be used to perform other tasks. The multiplatform libraries in Kotlin 1.3 cover everyday tasks such as HTTP, serialization and managing coroutines. Using the libraries is the easiest way to write multi platform code. You can also create custom multi-platform libraries which wrap platform-specific dependencies into a common API.

Tooling support for Kotlin/Native and Multiplatform

Kotlin 1.3 has tooling support for Kotlin/Native and multiplatform projects. This is available in IntelliJ IDEA Community Edition, IntelliJ IDEA Ultimate, and Android Studio. All of the code editing features such as error highlighting, code completion, navigation and refactoring are available in all these IDEs.

Ktor 1.0 Beta

Ktor is a connected applications framework. It implements the entire HTTP stack asynchronously using coroutines and has reached Beta.

Other features

Some other features in Kotlin 1.3 release include experimental support for inline classes, incremental compilation for Kotlin/JS, and unsigned integers. This release also features a sequence debugger for visualizing lazy computations, contracts to improve static analysis for library calls, and no-arg entry point to provide a cleaner experience for new users.

To know more details about all the changes, visit the changelog.

https://github.com/JetBrains/kotlin/blob/1.3.0/ChangeLog.md

Kotlin 开发者社区

国内第一Kotlin 开发者社区公众号,主要分享、交流 Kotlin 编程语言、Spring Boot、Android、React.js/Node.js、函数式编程、编程思想等相关主题。

img_f0a9a5e3c63edb2cda8899c204e13bbf.jpe
开发者社区 QRCode.jpg
相关文章
|
1月前
|
JSON 调度 数据库
Android面试之5个Kotlin深度面试题:协程、密封类和高阶函数
本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点。文章详细解析了Kotlin中的协程、扩展函数、高阶函数、密封类及`inline`和`reified`关键字在Android开发中的应用,帮助读者更好地理解和使用这些特性。
20 1
|
3月前
|
调度 开发者 UED
Kotlin 中的协程是什么?
【8月更文挑战第31天】
223 0
|
5月前
|
存储 Java 调度
Android面试题之Kotlin 协程的挂起、执行和恢复过程
了解Kotlin协程的挂起、执行和恢复机制。挂起时,状态和上下文(局部变量、调用栈、调度器等)被保存;挂起点通过`Continuation`对象处理,释放线程控制权。当恢复条件满足,调度器重新分配线程,调用`resumeWith`恢复执行。关注公众号“AntDream”获取更多并发知识。
127 2
|
6月前
|
移动开发 Android开发 开发者
构建高效Android应用:Kotlin与协程的完美融合
【5月更文挑战第25天】 在移动开发的世界中,性能和响应性是衡量应用质量的关键指标。随着Kotlin的流行和协程的引入,Android开发者现在有了更强大的工具来提升应用的性能和用户体验。本文深入探讨了Kotlin语言如何与协程相结合,为Android应用开发带来异步处理能力的同时,保持代码的简洁性和可读性。我们将通过实际案例分析,展示如何在Android项目中实现协程,以及它们如何帮助开发者更有效地管理后台任务和用户界面的流畅交互。
|
6月前
|
移动开发 数据库 Android开发
构建高效Android应用:探究Kotlin的协程优势
【5月更文挑战第22天】随着移动开发技术的不断进步,Android平台的性能优化已经成为开发者关注的焦点。在众多提升应用性能的手段中,Kotlin语言提供的协程概念因其轻量级线程管理和异步编程能力而受到广泛关注。本文将深入探讨Kotlin协程在Android开发中的应用,以及它如何帮助开发者构建出更高效、响应更快的应用,同时保持代码的简洁性和可读性。
|
6月前
|
移动开发 Android开发 开发者
构建高效安卓应用:Kotlin 协程的实践指南
【5月更文挑战第18天】 随着移动开发技术的不断进步,安卓平台亟需一种高效的异步编程解决方案来应对日益复杂的应用需求。Kotlin 协程作为一种新兴的轻量级线程管理机制,以其简洁的语法和强大的功能,成为解决这一问题的关键。本文将深入探讨Kotlin协程在安卓开发中的实际应用,从基本概念到高级技巧,为开发者提供一份全面的实践指南,旨在帮助读者构建更加高效、稳定的安卓应用。
|
6月前
|
移动开发 安全 Android开发
构建高效Android应用:Kotlin与协程的完美结合
【5月更文挑战第17天】 在移动开发领域,性能优化和流畅的用户体验是关键。对于Android平台而言,Kotlin语言凭借其简洁性和功能安全性成为开发的首选。与此同时,协程作为一种新的并发处理方式,在简化异步编程方面展现出巨大潜力。本文将深入探讨如何通过Kotlin语言以及协程技术,提升Android应用的性能和响应能力,并确保用户界面的流畅性。
|
6月前
|
移动开发 数据处理 Android开发
构建高效Android应用:Kotlin的协程与Flow的使用
【5月更文挑战第23天】 在移动开发领域,性能优化和异步编程一直是核心议题。随着Kotlin语言在Android开发中的普及,其提供的协程(coroutines)和流式编程(Flow)功能为开发者带来了革命性的工具,以更简洁、高效的方式处理异步任务和数据流。本文将深入探讨Kotlin协程和Flow在Android应用中的实际应用,以及它们如何帮助开发者编写更加响应迅速且不阻塞用户界面的应用程序。我们将通过具体案例分析这两种技术的优势,并展示如何在现有项目中实现这些功能。
|
5月前
|
Go Python
使用python实现一个用户态协程
【6月更文挑战第28天】本文探讨了如何在Python中实现类似Golang中协程(goroutines)和通道(channels)的概念。文章最后提到了`wait_for`函数在处理超时和取消操作中的作
51 1
使用python实现一个用户态协程
|
2月前
|
调度 Python
python3 协程实战(python3经典编程案例)
该文章通过多个实战案例介绍了如何在Python3中使用协程来提高I/O密集型应用的性能,利用asyncio库以及async/await语法来编写高效的异步代码。
20 0