javafx.event
Class WeakEventHandler<T extends Event>
- javafx.event.WeakEventHandler<T>
Type Parameters:
T - the event class this handler can handle
All Implemented Interfaces:
public final class WeakEventHandler<T extends Event> extends Object implements EventHandler<T>
Used in event handler registration in place of its associated event handler. Its sole purpose is to break the otherwise strong reference between an event handler container and its associated event handler. While the container still holds strong reference to the registered
WeakEventHandler proxy, the proxy itself references the original handler only weakly and so doesn't prevent it from being garbage collected. Until this weak reference is broken, any event notification received by the proxy is forwarded to the original handler.Since:
JavaFX 8.0
-
Constructor Summary
Constructors Constructor and Description WeakEventHandler(EventHandler<T> eventHandler)Creates a new instance ofWeakEventHandler.
-
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description voidhandle(T event)Forwards event notification to the associated event handler.booleanwasGarbageCollected()Indicates whether the associated event handler has been garbage collected.
-
Constructor Detail
-
WeakEventHandler
public WeakEventHandler(EventHandler<T> eventHandler)
Creates a new instance ofWeakEventHandler.Parameters:
eventHandler- the original event handler to which to forward event notifications
-
-
Method Detail
-
wasGarbageCollected
public boolean wasGarbageCollected()
Indicates whether the associated event handler has been garbage collected. Used by containers to detect when the storage of corresponding references to thisWeakEventHandleris no longer necessary.Returns:
trueif the associated handler has been garbage collected,falseotherwise
-
handle
public void handle(T event)
Forwards event notification to the associated event handler.Specified by:
handlein interfaceEventHandler<T extends Event>Parameters:
event- the event which occurred
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.