I am searching for a solution to my problem for a while now but I cannot find an answer which is specific for my question. I have a Class A which is abstract and Class B and C which extends class A. A and B are concrete classes. Class A implements function which will be inherited by V and C. Inside this function I want to create new object of B or C - the problem is that I don't know which object is that.
How can I achieve this?
public void colision(List<Organism> organisms) {
List<Organism> temp = new ArrayList<Organism>(organisms);
temp.remove(this);
for (Organizm organism : temp){
if (this.location == organizm.getLocation()){
if (this.getClass().equals(organism.getClass())){
//here is what I need to figure out
}
else{
...
}
}
}
}
}
createNewInstance()to A, and implement it in B and C. But you should really tell us what you're trying to achieve, at a higher level, becausethis.getClass().equals(organism.getClass())is a design smell.