Kotlin transmits variable length parameters to Java Variable Parameter instance code, kotlinjava

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.