Goal: enable JNI interop for Kotlin, so that anything that works through JNI in Java could be reproduced 1-to-1 in Kotlin
The following definition is present in the library:
package kotlin.jvm Retention(RetentionPolicy.SOURCE) public annotation class native
This annotation is applicable to
A declaration marked with this annotation is referred to as a native declaration.
Checks to perform:
inline
reified
type parameters NOTE: this is achieved through prohibiting inline
, as reified
is only allowed on inline-functions nowNOTE: native members can override open (or abstract) members of supertypes
Intuition: a JVM method whose source declaration is native is marked with the ACC_NATIVE
flag, and has no CODE
attribute.
A native member of an object marked native
and platformStatic
is translated in a straightforward way: there is only one JVM method corresponding to it, and it is marked as ACC_NATIVE
.
A member of a companion object of class C
marked native
and platformStatic
yields two JVM methods:
C
that is marked ACC_NATIVE
;C$object
that is not marked ACC_NATIVE
and its body delegates to the native static method.A native member of package p
yields one JVM method:
PPackage
which is marked with ACC_NATIVE
flag.A property can not be marked native
. A property accessor can be marked native
if it has no body (i.e. it is a default accessor). In this case the generated code is the same as for a native function defined in the same context as the property.
Example:
val foo: Int [native] get