事务(JDBC、Hibernate、Spring)

1、创建对象的几种方式

1)new Object

2)利用反射。调用Class实例的newInstance()方法,或者利用Class实例得到Constructor实例,进而调用其newInstance()方法。

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException,
InstantiationException, NoSuchMethodException, InvocationTargetException {
Class clazz = Class.forName("java.lang.Integer");
Constructor constructor = clazz.getConstructor(String.class);
Integer integer = (Integer) constructor.newInstance("123");
System.out.println(integer);
}

3)利用clone()方法。需要这个类实现Cloneable接口。

    public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList(Arrays.asList(1, 2, 3));
List list0 = (List) list.clone();
list.remove(1);
System.out.println(list);
System.out.println(list0);
}

ArrayList类实现了Cloneable接口,故可以调用clone()方法。

4)反序列化。

上一篇:Fiddler 模拟post 提交


下一篇:jQuery实现Ajax请求时,页面显示等待的效果,超过指定请求时间后,进行其他操作