My first question here is so gentle.
I need arguments for the following code:
public class Example {
private String name;
private int age;
...
public Example(Example e) {
this.name = e.name;
this.age = e.age;
}
...
}
I believe this violates the modularity of the instance passed to the copy constructor. This is what I consider correct:
public class Example {
private String name;
private int age;
...
public Example(Example e) {
this.setName(e.getName());
this.setAge(e.getAge());
}
...
}
A friend put forth a valid point of view, saying that in the design of the copy we must create the object as quickly as possible. And adding getter / setter methods will lead to unnecessary overhead.
I am standing at the crossroads. Can you shed some light?
source
share