I have 2 classes
class Immutable {
public int i;
public static Immutable create(int i){
return new Immutable(i);
}
private Immutable(int i){this.i = i;}
public int getI(){return i;}
}
and
class Immutable1 {
public int i;
public static Immutable1 create(int i){
return new Immutable1(i);
}
private Immutable1(int i){this.i = i;}
public int getI(){return i;}
}
Both have same methods and same instance variables. As per my understanding state of the class are same (int i) and both have same behaviour(same number of methods)
Hence one is exact copy of another.
In another class if I do
Immutable immutable=Immutable.create(1);
Immutable1 immutable1=Immutable1.create(1);
immutable1=immutable;// I get error here
The error is type mismatch :can not convert from Immutable to Immutable1