T
- the object-type returned by this class.public class SettingsFactory<T> extends Object
Constructor and Description |
---|
SettingsFactory() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
getInstance(String settingsField,
Object... args)
Creates a new class of the class given in the settings field.
|
public SettingsFactory()
public static <T> T getInstance(String settingsField, Object... args)
If the loaded class has a getInstance() method that matches the given arguments, that will be called to create the class, otherwise a matching constructor will be called, if it exists. This sequence allows for creating singletons.
Due to limitations of the Java Reflection API, the parameters of the getInstance method declared on the loaded class must match the given arguments exactly, without subclassing, interface implementation or unboxing. In particular, since any primitive types are automatically boxed when passed to this method, getInstance() methods with primitive type formal parameters will not be found.
T
- the object-type returned by this method.settingsField
- A field in the Settings class.args
- The arguments that will be passed to the getInstance method or the constructor. These will also be
used to determine which getInstance method or constructor to find.ArgumentNotValid
- if settingsField is null or the invoked method or constructor threw an exception.IOFailure
- if there are unrecoverable errors reflecting upon the class.PermissionDenied
- if the class or methods cannot be accessed.Copyright © 2005–2015 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.