.Net MemberwiseClone vs Java Clone

I am converting C # code to Java. There are many different places that rely on .NET MemberwiseClone in the code that I convert.

It seems that they both make a shallow copy. Is it possible to simply replace these calls with Java clone() ? I want to make sure that there are no minor differences that can make fixing errors difficult.

+7
source share
1 answer

Assuming that calling clone() in Java just calls the implementation of Object.clone() , I assume that they have the same behavior:

  • Another object of the same class was created.
  • Fields are copied (up and down the inheritance hierarchy)
  • All copies are done in a small way.
  • Custom code is not executed (constructors, etc.)
+6
source

All Articles