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?
Obviously it’s sometimes OK, especially if you’re modifying an existing program where you don’t really have the option to redesign everything, but still have a think anyway.
I’m not sure where the list is relevant, unless we’re talking about the actual bytecode required (which I didn’t think you were?)