I have a very simple question.
Can 2 classes share the same Super class instance? I know the answer is no, because super is the instance itself, but I was really there was some workaround...
public class Parent{
private final int parentId;
private static final HashMap<Integer,Parent> parentMap = new HashMap<Integer,Parent>();
private Parent(int i){
parentId = i;
parentMap.put(i,this);
}
public static Parent newInstance(int i)
{
if(parentMap.containsKey(i))
return parentMap.get(i);
return new Parent(i);
}
}
/* Other class */
public class ExtendedParent extends Parent{
public ExtendedParent(int i){
super(i);//I should use the factory at this point...
}
public static main(String[] args){
/*What I am trying to achieve*/
Parent p1 = new ExtendedParent(1);
Parent p2 = new ExtendedParent(1);
if(p1.equals(p2))
System.out.println("This is what i aim to get!!!!");
}
}
Remade the code to demonstrate my problem clearly.
Can someone help me out? =D
Thanks in advance!