最近一个我能找到的是这个线程:为什么我必须创建int数组而不是直接将其作为参数传递的原因?
How to pass int array as an argument to a constructor?
答案是明确的,你定义一个int [] tempArray和使用tempArray作为参数。但是,我的问题是为什么不能直接写int数组作为参数。
的代码示例是这样的:
public static void main (String[] args) {
NewClass test = new NewClass();
// int[] tempArray = {1, 2, 3};
// test.doSomething(tempArray);
test.doSomething({1, 2, 3});
}
你需要'new int [] {1,2,3}' – 3kings