5
我有一個Java功能的可變參數方法:調用Java從科特林
public static void initialize(@NonNull Activity activity, Settings... settings) {}
我想從科特林稱之爲:
fun initialize(activity: Activity, vararg settings: settings) = JavaClass.initialize(activity, settings)
不過,這並不編譯,告訴我,有類型不匹配,Settings
是必需的,但參數是kotlin.Array<out Settings>
我看到它試圖與signture
與之匹敵public static void initialize(@NonNull Activity activity, Settings settings) {}
,但我想用
public static void initialize(@NonNull Activity activity, Settings[] settings) {}
此外,這裏的約可變參數的文檔和傳播操作參考:https://kotlinlang.org/docs/reference/functions.html#variable-number-of-arguments-varargs – hotkey