I don't really know if this is possible but I've been trying to accept a Consumer<? extends Event>
for a while, but I keep getting a variable mismatch whenever invoking it.
Here is my example code:
public static void main(String[] args) {
ArrayList<Consumer<? extends Event>> x = new ArrayList<>();
Consumer<ExampleEvent> y = e -> {}; // ExampleEvent extends Event
x.add(y);
for (Consumer<? extends Event> z : x) {
z.accept(new Event());
}
}
Every time I get an error saying that it's an argument mismatch
I'm using eclipse on windows
here is the error: The method accept(capture#5-of ? extends Event) in the type Consumer<capture#5-of ? extends Event> is not applicable for the arguments (Event)