-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVarargType.java
More file actions
45 lines (36 loc) · 938 Bytes
/
Copy pathVarargType.java
File metadata and controls
45 lines (36 loc) · 938 Bytes
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
41
42
43
44
45
package unit5;
public class VarargType {
//getClass()将产生对象的类
static void f(Character... args) {
System.out.println(args.getClass());
System.out.println("length of args:" + args.length);
}
static void g(int... args) {
System.out.println(args.getClass());
System.out.println("length of args:" + args.length);
for (int i : args) {
System.out.println(i);
}
}
public static void main(String[] args) {
f('a');
f();
System.out.println();
g(1);
g();
System.out.println("int[]:" + new int[0].getClass()); //可变参数列表不依赖于自动包装机制
System.out.println();
g(1,new Integer(2),3); //单一参数列表中将类型混合在一起,自动包装机制有选择的将参数提升为Integer
}
}
/*
class [Ljava.lang.Character;
length of args:1
class [Ljava.lang.Character;
length of args:0
class [I
length of args:1
class [I
length of args:0
int[]:class [I
* */