I want to have the same static variable with a different value depending on the type of class.
So I would have
public class Entity
{
public stat
Use an abstract method:
public class Entity
{
public abstract Bitmap getSprite();
public void draw(Canvas canvas, int x, int y)
{
canvas.drawBitmap(getSprite(), x, y, null);
}
}
public class Marine extends Entity
{
public Bitmap getSprite() {
return /*the sprite*/;
}
}
The sprite returned by getSprite can be a static if you like. Nice things about this approach:
You can't (easily) forget to include a sprite in your subclass, since the compiler will complain if you don't implement the abstract method.
It's flexible. Suppose a Marine should look different once he "levels up". Just change Marine's getSprite method to take the level into account.
It's the standard OO-idiom for this sort of thing, so people looking at their code won't be left scratching their heads.