I have a java function:
public static void initialize(@NonNull Activity activity, Settings... settings) {}
I want to call it from kotlin:
fun initialize(activity: Activity, vararg settings: settings) = JavaClass.initialize(activity, settings)
But it does not compile, telling me that there is type mismatch, Settings is required, but the argument is kotlin.Array
I see that it's trying to match it with signture
public static void initialize(@NonNull Activity activity, Settings settings) {}
but I want to use
public static void initialize(@NonNull Activity activity, Settings[] settings) {}
解决方案
You should use the following syntax:
fun initialize(activity: Activity, vararg settings: settings) =
JavaClass.initialize(activity, *settings)