I have a Interface IEvent that looks like this:
public abstract interface IEvent<T> {
public abstract void handleEvent(T payload);
}
and 2 Interfaces with a concrete generic type that looks like this:
public interface IKeyDownEvent extends IEvent<KeyDownEventPayload> {}
public interface IKeyUpEvent extends IEvent<KeyUpEventPayload> {}
Both KeyUpEvent and KeyDownEvent are extending from EventPayload.
How do I go about and iterate over a ArrayDeque and only call handleEvent() for classes that implement IKeyDownEvent but not for example IKeyUpEvent?
I tried this but it seem to not work:
if (payload.getClass() == ev.getClass().getGenericSuperclass())
ev.handleEvent(payload);