Access of private field of another object in copy constructors - Really a problem?
- by DR
In my Java application I have some copy-constructors like this
public MyClass(MyClass src) {
this.field1 = src.field1;
this.field2 = src.field2;
this.field3 = src.field3;
...
}
Now Netbeans 6.9 warns about this and I wonder what is wrong with this code?
My concerns:
Using the getters might introduce unwanted side-effects. The new object might no longer be considered a copy of the original.
If it is recommended using the getters, wouldn't it be more consistent if one would use setters for the new instance as well?