header/impl 关键字在 kotlin 中的含义是什么?

2024-03-30

就在不久前,当我探索 Kotlin github 存储库时,我发现了一些有趣的事情:Kotlin 现在似乎有一个 header 关键字。

收藏H.kt https://github.com/JetBrains/kotlin/blob/be95f66b1343af2a4df2fd022d1ddd6000d5a017/libraries/stdlib/common/src/kotlin/CollectionsH.kt:

 open header class ArrayList<E> : MutableList<E> {

 //...

 header inline fun <reified T> Array<out T>?.orEmpty(): Array<out T>

这是什么意思?它是一些公共可用的功能还是帮助 stdlib 开发的内部功能?


编辑:似乎有一个impl与标题结合使用的关键字。那是什么?


更新2:

多平台项目支持已发布。

  • 公告链接 https://blog.jetbrains.com/kotlin/2017/11/kotlin-1-2-released/
  • KotlinConf 2017 的多平台应用程序 https://github.com/JetBrains/kotlinconf-app

更新1:

The impl and header关键字已替换为actual and expect在 Kotlin 多平台项目的预览版中。

官方文档可以找到here https://kotlinlang.org/docs/reference/multiplatform.html或者在这个 GitHub永久链接 https://github.com/JetBrains/kotlin-web-site/blob/b056703475e9a7e586c588d634a23b36132e0620/pages/docs/reference/multiplatform.md


曾在这个视频 https://vimeo.com/215556547#t=868s14:28。

From the slides https://www.slideshare.net/abreslav/future-of-kotlin-how-agile-can-language-development-be: Slide #14

基本上,header在为跨多个平台(JVM、JS 和 Native)工作的模块编写接口时将使用。这impl在为特定平台编写实现时将使用关键字。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

header/impl 关键字在 kotlin 中的含义是什么? 的相关文章

随机推荐