I 've been read documents about clone object and my conclusion is clone objects is bad practice.
Is one of the best way to make a new object with the same values that another ?
Example:
class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name){
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age){
this.age = age;
}
}
public class AnotherClass{
Student guy = new Student();
guy.setName("Mike");
guy.setAge(20);
Student guy2 = makeClone(guy); //now i get a new guy with the same values of the first guy
private Student makeClone(Student oldStudent){
Student newStudent = new Student();
newStudent.setName(oldStudent.getName());
newStudent.setAge(oldStudent.getAge());
return newStudent;
}
}