Class SettingsFactory<T>

    • Constructor Detail

      • SettingsFactory

        public SettingsFactory()
    • Method Detail

      • getInstance

        public static <T> T getInstance​(String settingsField,
                                        Object... args)
        Creates a new class of the class given in the settings field.

        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.

        Type Parameters:
        T - the object-type returned by this method.
        Parameters:
        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.
        Returns:
        A new instance of type T created by calling getInstance() or by invoking a constructor.
        Throws:
        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.