java - Create in a simple way a copy of an object -
consider code below:
project project1 = new project("string1","string2","string3","string4","string5", ...); project project2 = project1; here, project2 not copy of project1, because points same object. significate if edit project2, edit project1.
i want project2 independent of project1. suppose can make constructor project param like:
public project(project project) { this.string1 = project.getstring1(); this.string2 = project.getstring2(); ... } i case, have 15 attributes in project class, doing require me write big constructor.
is there better way ? :)
thanks !
no, there not better way that. use clone, but... don't. don't use clone.
Comments
Post a Comment