WidgetData
The WidgetData
class is a Java record that encapsulates the data needed to create a widget. It uses Java’s Supplier
functional interface to provide a factory method for creating widgets.
This class is mostly used for loading widgets. This provides an automatic way of producing widget (also known as widgetFactory).
Key Components
name: A
String
that represents the name of the widget.description: A
String
that provides a description of the widget.widgetFactory: A
Supplier<T>
whereT
extendsWidget
. This is a factory method for creating instances of the widget.
Methods
name(): This method returns the name of the widget.
description(): This method returns the description of the widget.
createWidget(): This method uses the
widgetFactory
to create a new instance of the widget.
Usage
Here’s an example of how you might use the WidgetData
class:
Last updated
Was this helpful?