I was implementing an immutable class whose structure is as below :
public final class A{
private final B bOb;
public A(){
bOb = new B();
}
public A(A a){
bOb = new B(a.bOb);
}
public A addData(Type data){ // Type - Integer,String,char,etc.
A newA = new A(this); //making a copy of the object that is calling addData method
newA.bOb.add(data);
return newA;
}
}
Is this implementation correct ? Let's say the object bOb is a list.