What does it mean to clone() an object?

前端 未结 2 1484
情深已故
情深已故 2021-02-15 18:31

What is object cloning in vb6 or java? In what situation do we use a clone? What does cloning objects mean? Can any one tell me with example please.

2条回答
  •  旧时难觅i
    2021-02-15 18:49

    Generaly speaking objects are passed by reference. So if you say $objB=$objA you are not getting a new object; you are getting a new name for the same object. However, if you say $objB= clone $objA you get a copy of $objA. In the first case, whatever you do to $objB also happens to $objA. In the 2nd case, $objB is independent.

提交回复
热议问题