Whether it is the only way to convert 'nullable case vararg parameter' from java to Kotlin replace with Array<Some>?

Whether it is the only way to convert ‘nullable case vararg parameter’ from java to Kotlin replace with Array? .

In Java:

void inStream(int eventType, @Nullable String action, StamperNote... notes);

Whether it is the only way to match the same function in Java use Kotlin:

fun inStream(eventType: Int, action: String?, notes: Array<StamperNote>? = null)

If so, why the IDEA Gradle plugin convert it from Java to Kotlin with vararg syntax, what don’t match the same thing I want in Java.

The way to match the same signature in Kotlin is to use a vararg parameter: fun inStream(eventType: Int, action: String?, vararg notes: StamperNote). Your conversion requires the caller to wrap the arguments into an array explicitly.

Note that vararg parameters are, as a rule, never nullable, because in Java there is no good way to distinguish between passing null as the entire vararg array versus passing null as a single element of a non-null vararg array.

1 Like

Thanks! got it.