I disagree here. Depite the naming (should be more like 'LocationProvider' or something instead of 'IsCamObject'), it's a perfectly fine solution to separate interfaces to access specific information from the overall class hierarchy.
But you are right, that in this case it would probably be simpler to make a base class (Entity or ScreenObject or something), simply extend all Player, Enemy, Shot, whatever classes from it and make the following object of this base type.
1
| g.translate((Player)following.x, (Player)following.y); |
it crashes saying that following can't be type casted to Player.
are you sure it doesn't say "following
.x can't be type casted to Player"?
1
| g.translate(((Player)following).x, ((Player)following).y); |
should work - but wouldn't be a real solution, since you would still be forced to only use Player objects in following. It's even worse, since it would shift the possible error from compile time to runtime. So makes it harder to debug.