Hello Java Gaming world! I have a question about type checking. So let me describe my situation.
I have this interface
public interface State<T extends Entity> {
public void init(T t);
public void update();
public void render(Screen s);
public void processCollision(T t);
public T getEntity();
}
And this class:
public abstract class MobState<T extends Mob> implements State<Mob> {
protected T m = null;
// more fields defined here...
// some methods defined here...
}
In my code, Mob extends Entity, and MobState implements State. Ball extends Mob, and BallNormalState extends MobState:
public class BallNormalState extends MobState<Ball> {
public void init(Mob m) {
this.m = (Ball) m;
}
// more methods defined here...
}
My question is, in BallNormalState::init, I can’t pass anything more specific than Mob because of the interface, so how can I best enforce type checking? It needs to be Ball and not any other type of Mob! Thanks for any advice! 8)