how to clone an object in android?

前端 未结 6 1717
醉梦人生
醉梦人生 2021-01-07 18:43

What would be the best way to copy/clone an object in java/android?

rlBodyDataObj rlbo = bdoTable.get(name);

Right now the code assigns an

6条回答
  •  暖寄归人
    2021-01-07 19:31

    i wish to implement with : copy constructor

    class DataObj {
      private String tag;
    
      public DataObj(DataObj another) {
        this.tag= another.tag; // you can access  
        ...
      }
    }
    

    Every object has also a clone method which can be used to copy the object, but It's way too easy to create a class and do improper clone method. If you are going to do with implement clone method, read at least what Joshua Bloch has to say about it in Effective Java.

提交回复
热议问题