-1

I was wondering how we can clone an inheritance hierarchy in java. would you just implement cloneable on the class that you wish to clone?

Chandrashekhar Swami
  • 1,742
  • 23
  • 39
Ciaran
  • 697
  • 1
  • 12
  • 35

1 Answers1

1

Simply implementing cloneable is not enough. Why cloneable is broken can be read in the answer to this question.

If you want a deep clone you could serialize and deserialize the object. That way you are sure that everything is properly cloned. If that is not fast enough (be sure to profile first) you can implement the clone method yourself.

Community
  • 1
  • 1
Burkhard
  • 14,596
  • 22
  • 87
  • 108