Kotlin transmits variable length parameters to Java Variable Parameter instance code, kotlinjava
This article mainly studies how Kotlin transfers variable length parameters to Java variable parameters. The specific implementation code is as follows.
Defines Java Variable Parameter Methods
Package com. tcl. john. studymvvm. utils;/*** call Java method tool class * Created by ZhangJun on. */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 the variable length parameter and calls the above Java method
// Test whether Kotlin passes the variable length parameter to the Java Variable Parameter Method var numbers: IntArray = intArrayOf (1, 2, 3, 4, 5) CallJavaUtils. addNumbers ("add", * numbers)
Summary
The above is all about passing a variable length parameter to the Java Variable Parameter instance code in Kotlin. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!