Well, casting up and changing the object type is not possible in Java. So now I am kinda stuck.
I have a root class called GameObject. It contains a function that looks like this:
public GameObject getClone(float x, float y)
{
GameObject go = new GameObject();
//Clone the data here
return go;
}
Then we have MovableObject which extends GameObject:
public MovableObject getClone(float x, float y)
{
MovableObject mo = (MovableObject) super.getClone(x,y);
//Clone the data here
return mo;
}
The cast operation will trigger ClassCastException.
Since a MovableObject have all the variables GameObject have + more, it would make sense to call the super class function first and then continue on the divided class function.
Are there any efficient ways to solve this?