The main research in this paper is Kotlin's method of passing variable length parameters to Java variable parameters. The specific implementation code is as follows.
Define Java variadic parameter methods
package com.tcl.john.studymvvm.utils;/** * Tool class that calls Java methods* Created by ZhangJun on 2017/10/25. */public class CallJavaUtils { public static int addNumbers(String name, int... args) { int result = 0; for (int i = 0; i < args.length; i++) { result += args[i]; } return result; }}Kotlin passes variable length parameters and calls the above Java method
//Test Kotlin passes variable length parameters to Java variadic parameter method var numbers:IntArray = intArrayOf(1, 2, 3, 4, 5)CallJavaUtils.addNumbers("add", *numbers)Summarize
The above is all about Kotlin passing variable-length parameters to Java variable-parameter instance code, I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!