I have lots of classes and circular references among them (e.g. an in class A
, I have a set of objects from class B
and class B
has an attribute as an object of class A
etc.)
When I try to copy everything from an object to another and modify the base object, because of the lists, I lose information.
Is there a way to copy every single bit from an object to another?
Edit:
Consider the following classes
class Book
{
private Set<Page> pages;
String title;
}
class Page
{
private Set<String> lines;
private int number;
private int numberOfLines;
private Book book;
}
should I use Cloneable
for both or using just for Book
is sufficient?
Could you please help me to write a copy constructor (or a method to copy) for Book
class?