-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableParameters1.java
More file actions
40 lines (35 loc) · 1.05 KB
/
Copy pathVariableParameters1.java
File metadata and controls
40 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.company.array;
import sun.reflect.generics.tree.VoidDescriptor;
/**
* @author 苏东坡
* @company 公司
* @create 2021-07-29-8:25 上午
*
* 可变参数: 作用提供了一个方法, 参数的个数是可变的,解决了部分方法的重载问题
* int...num
* double...num
* boolean...num
* 可变参数在JDK1.5之后加入的新特性
* 方法的内部对可变参数的处理跟数组是一样的
* 可变参数和其他数据一起作为形参的时候,可变参数一定放最后
*/
public class VariableParameters1 {
public static void main(String[] args) {
method(10);
method();
method(10, 20, 30);
method(10, 20, 30, 40);
method(new int[]{10, 20, 30});
method2(10, 20, 30, 40);
}
public static void method(int... num) {
System.out.println("1-----");
for (int i : num) {
System.out.print(i + "\t");
}
System.out.println();
}
public static void method2(int num, int... num1) {
System.out.println("2---");
}
}