RFR: 8306021: Add event handler management to EventTarget
Michael Strauß
mstrauss at openjdk.org
Sat Apr 15 04:55:41 UTC 2023
On Wed, 12 Apr 2023 18:19:11 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
> This PR adds the following methods to the `EventTarget` interface:
> 1. `addEventHandler`
> 2. `removeEventHandler`
> 3. `addEventFilter`
> 4. `removeEventFilter`
This PR assumes that changing the first method signature to the second is a binary-compatible change:
1. <E extends Event> void addEventHandler(EventType<E>, EventHandler<E>)
2. <E extends Event> void addEventHandler(EventType<E>, EventHandler<? super E>)
To verify this, I've created the following test:
import java.util.function.Consumer;
// Test.java
public class Test {
public static <T> void test(Consumer<T> c) {
System.out.println("it works");
}
}
// Main.java
public class Main {
public static void main(String[] args) {
Consumer<String> c = param -> {};
Test.test(c);
}
}
Note that `Consumer`, like `EventHandler`, only uses the generic type parameter as an _input_ argument.
After compiling both files, I changed the signature of the `test` method to `void test(Consumer<? super T>)`.
Then I made sure to _only_ recompile the `Test.java` file and ran the `Main` program, which succeeded.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1090#issuecomment-1509495524
More information about the openjfx-dev
mailing list