Class Initializer<T>
- Type Parameters:
T- the type of object that this initializer will create
- All Implemented Interfaces:
Serializable,Loadable
- Direct Known Subclasses:
LabyrinthPanelInit
T.
Initializer is used to supply a method of creating an object of type T.
The class does not load anything directly, but custom initializers can be loaded via
InitializersPluginLoader if needed. Subclasses should implement the getName()
and create(Object...) methods to define the specific initialization logic.
In the application, an initializer is typically used in the context of creating
objects like LabyrinthPanel, as shown in LabyrinthPanelInit,
where the initializer provides a way to create specific instances of complex objects.
The generic type T represents the type of object that will be created, and the
getType() method returns the class of that type.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newInitializerand extracts the generic typeTfrom the subclass. -
Method Summary
-
Constructor Details
-
Initializer
public Initializer()Constructs a newInitializerand extracts the generic typeTfrom the subclass.This constructor uses reflection to determine the actual type of
Tbased on the subclass that extendsInitializer. If the type parameterTis not specified, a runtime exception will be thrown.- Throws:
RuntimeException- if the type parameterTis not specified in the subclass
-
-
Method Details
-
getType
Returns theClassobject of the typeT.This method provides access to the type of object that will be created by this initializer.
- Returns:
- the
Classobject representing the type ofT
-
getName
Returns the name of the initializer.This method must be implemented by subclasses to provide a human-readable name for the initializer. This name is typically used to identify the initializer in the application.
- Returns:
- the name of the initializer
-
create
Creates an instance of typeTusing the provided arguments.This method must be implemented by subclasses to define how an object of type
Tis created. Theobjectsparameter can contain any necessary data required for object creation, and the method should return the created instance. It may throw exceptions if the arguments are invalid or if the creation fails for any reason.- Parameters:
objects- the arguments needed to create an object of typeT- Returns:
- an instance of type
T - Throws:
IllegalArgumentException- if the arguments are invalid or insufficient for object creation
-