Suppose I have it
interface Movable {
And I have
class Car implements Movable {
And also maybe with me
class Bike implements Movable {
I noticed that if I had this:
ArrayList<Movable> movableThings = new ArrayList<Movable>(); movableThings.add(some kind of Car) movableThings.add(some kind of Bike) movableThings.add(some kind of Bike)
It can be called:
for(Movable m: movableThings)
But if I call it, I get incompatible types:
for(Bike b: movableThings)
Can someone explain and maybe suggest a better way? I know I can use foreach Movable m: movableThings and then use instanceof to test bikes, but is there any other way?
Edit: ok thanks for clarifying the guys ... so I think I either use instanceof or redesign my game
source share