- new
- Class的newInstance()
- Constructor的newInstance() // 2,3即为反射
- clone
- 使用反序列化
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
public class Main implements Serializable {
public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IOException {
ArrayList<Integer> list1 = new ArrayList<>();
ArrayList<Integer> list2 = (ArrayList<Integer>) Class.forName("java.util.ArrayList").newInstance();
ArrayList<Integer> list3 = ArrayList.class.newInstance();
Constructor<ArrayList> constructor = ArrayList.class.getConstructor();
ArrayList<Integer> list4 = constructor.newInstance();
ArrayList<Integer> list5 = (ArrayList<Integer>) list1.clone();
ObjectInputStream in = new ObjectInputStream(new FileInputStream("data.obj"));
ArrayList<Integer> list6 = (ArrayList<Integer>) in.readObject();
}
}