Skip to main content

Arrays (T[])

Arrays are represented with the most common and efficient native data structures, such as std::vector<T> in C++ or Array<T> in Swift and Kotlin.

import { type HybridObject, Apple } from 'nitro-core'

@Apple(...)
export declare class Contacts extends HybridObject {
getAllUsers(): User[]
}

Kotlin PrimitiveArray​

As a performance improvement, the JNI (C++ -> Kotlin interface) provides Primitive Array datatypes which can avoid boxing primitives into Objects, and provides bulk copy methods. This makes all array operations a lot faster, and Nitrogen is smart enough to ✨automagically✨ use Primitive Arrays whenever possible. This will replace the following arrays:

ULongArray shares its LongArray with JNI, so UInt64[] crosses without copying. Kotlin still marks ULongArray as experimental, so Nitrogen's generated +autolinking.gradle opts your module in to kotlin.ExperimentalUnsignedTypes. Generated code and your implementations can use it without warnings. Other modules that use these APIs, such as your app, need their own opt-in.