创建对象的4种方式?

1.使用new关键字
2.使反射进行
a 通过Class类的newInstance方法 -> Class.forname().newInstance();
b 通过Constructor类的newInstance方法 ->
Constructor constructor = Employee.class.getConstructor();
Employee emp3 = constructor.newInstance();
3.使用clone(克隆)方法
4.使用反序列化

发布了17 篇原创文章 · 获赞 0 · 访问量 1030

猜你喜欢

转载自blog.csdn.net/weixin_41980692/article/details/105720954