gpt4 book ai didi

Java 将数组转换为参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:16:44 25 4
gpt4 key购买 nike

有没有办法将数组转换为参数列表......?

main(){
//"a" is an array or a list or some collection
myPrint(a.SomeMethod);
}

void myPrint(int a){
//Do Stuff to arguments
}

void myPrint(int a, int b){
//Do Stuff to arguments
}

void myPrint(int a, int b, int c){
//Do Stuff to arguments
}

我想将“a”转换为参数/参数列表,以便它自动调用适当的函数。

最佳答案

main(){
int[] a = {1,2,3};
MyPrint(a);
}

void MyPrint(int... x){
//Do Stuff to arguments (accessing them by its index)
}

关于Java 将数组转换为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3993869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com