How do I copy an object in Java?

后端 未结 23 2670
终归单人心
终归单人心 2020-11-21 04:50

Consider the code below:

DummyBean dum = new DummyBean();
dum.setDummy(\"foo\");
System.out.println(dum.getDummy()); // prints \'foo\'

DummyBean dumtwo = du         


        
23条回答
  •  鱼传尺愫
    2020-11-21 05:23

    Yes, you are just making a reference to the object. You can clone the object if it implements Cloneable.

    Check out this wiki article about copying objects.

    Refer here: Object copying

提交回复
热议问题