30 lines
781 B
Java
30 lines
781 B
Java
// housekeeping/VarargType.java
|
|
// ©2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
|
|
public class VarargType {
|
|
static void f(Character... args) {
|
|
System.out.print(args.getClass());
|
|
System.out.println(" length " + args.length);
|
|
}
|
|
static void g(int... args) {
|
|
System.out.print(args.getClass());
|
|
System.out.println(" length " + args.length);
|
|
}
|
|
public static void main(String[] args) {
|
|
f('a');
|
|
f();
|
|
g(1);
|
|
g();
|
|
System.out.println("int[]: " + new int[0].getClass());
|
|
}
|
|
}
|
|
/* Output:
|
|
class [Ljava.lang.Character; length 1
|
|
class [Ljava.lang.Character; length 0
|
|
class [I length 1
|
|
class [I length 0
|
|
int[]: class [I
|
|
*/
|