So I am curious, say I have this situation:
I have a base Entity class, it is not specialized in anything and only has a few members, once of them being a sprite.
So say I have a Player class that extends from this but the Player also implements an interface called Drawable.
I put a bunch of entities into an array, only the player implements this.
Is it faster to just do this:
if(sprite != null)
entity.draw(batch)
Or is it better to check for implementation like so:
if(entity.getClass().isAssignableFrom(Drawable.class)){
Drawable drawable = (Drawable) entity;
drawable.draw(batch);
}
Although this is an example, and has quite a few flaws (why would a base class have a sprite if it is not specialized etc) but it is mainly a quick scenario I could think of.
What would be the logical one to do? Which would be faster?