What does header/impl keyword mean in kotlin?

2019-04-27 20:03发布

问题:

Just moments ago when I was exploring the Kotlin github repo, I found something interesting: Kotlin now seems to have a header keyword.

CollectionsH.kt:

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

 //...

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

What does it mean? Is it some public available feature or a internal feature to help stdlib development?


EDIT: There seems to be a impl keyword that work in conjunction with header. What's that?

回答1:

UPDATE 2:

Multiplatform project support has been released.

  • Link to the announcement
  • Multiplatform application for KotlinConf 2017

UPDATE 1:

The impl and header keywords have been replaced by actual and expect in the preview release of multiplatform projects for Kotlin.

The official documentation can be found here or at this GitHub permalink


It was talked about in this video at 14:28.

From the slides:

Basically, header will be used when writing interfaces for modules that work across multiple platforms (JVM, JS, and Native). Theimpl keyword will be used when writing an implementation for a specific platform.



标签: kotlin