0

I wanted to check if this a deep copy constructor I have created.

private int redPixel;
private int greenPixel;
private int bluePixel;

public Pixel(Pixel other)
{
  this.redPixel = other.redPixel;
  this.greenPixel = other.greenPixel;
  this.bluePixel = other.bluePixel;
}
man2006
  • 53
  • 2
  • 7
  • See [Chandra's](http://stackoverflow.com/a/9834683/438154) answer about what a deep copy is. – Sotirios Delimanolis Apr 10 '15 at 22:23
  • What makes you think this is not a *deep copy*? – Willem Van Onsem Apr 10 '15 at 22:32
  • @CommuSoft because from what I understand that this is a shallow copy but I'm trying to create a deep copy without using Serialization and this is where my confusion stems from. – man2006 Apr 10 '15 at 22:48
  • All primitive types (`int`,`long`,`boolean`,`float`,...), *copy* the value. All other values copy the reference (and thus must be cloned as well). Since in this case, you are only dealing with `int`s, it's a deep copy. – Willem Van Onsem Apr 10 '15 at 22:50

0 Answers0