一味宠爱|七夕面向对象编程,你知道Java有哪些创建对象的方式吗?( 二 )

p1 = Class.forName("com.yky.Girlfriend");Constructor constructor = p1.getConstructor(String.class, Integer.class);Girlfriend girlfriend04 = (Girlfriend) constructor.newInstance("k", 18);System.out.println(girlfriend04);//3、使用object类的clone方法Girlfriend girlfriendClone = (Girlfriend) girlfriend04.clone();System.out.println("girlfriendClone="+girlfriendClone);//4、使用序列化反序列化生成对象Girlfriend clone = ObjectUtils.clone(girlfriend04);System.out.println("clone"+clone);System.out.println("girlfriend04和反序列化生成的clone相等吗");System.out.println(clone == girlfriend04);}来源:;depth_1-utm_source=distribute.pc_category.none-task-blog-hot-2.nonecase&request_id=


推荐阅读