java中的Class和可变参数
package javase;
import java.util.ArrayList;
import java.util.List;
public class Tool {
public static Object copy(Object object) throws Exception {
// 得到对象的类型信息
Class cla = object.getClass();
System.out.println(cla.getName());
List<String[]> list = new ArrayList<String[]>();
String[] strings = new String[] {};
Class<?>[] cl = new Class[] {};
Class[] c = new Class[] {};
cla.getConstructor(new Class[] {});
Class<?> cl2 = Integer.class;
Class<?> cl3 = Double.class;
Class<Integer> cl4 = Integer.class;
return null;
}
public static void main(String[] args) throws Exception {
copy(new Son());
test("abc");
test();
// test(null);
test("123", "hello");
test(new String[] {});
test(new String[] { "6688", "ok", "go" });
List<String> list = new ArrayList<String>();
String[] array = (String[]) list.toArray(new String[0]);
test(array);
String[] array2 = list.toArray(new String[0]);
test(array2);
}
public static void test(String... strings) {
System.out.println("----------------------------------");
for (int index = 0; index < strings.length; index++) {
System.out.println(strings[index]);
}
System.out.println("----------------------------------");
}
}