Class StaticMethodCaller


  • public final class StaticMethodCaller
    extends Object
    Helper to call a no-arg constructor or static getter to obtain an instance of a specified type. This is used for logging platform "plugins". It is expected that these constructors/methods will be invoked once during logger initialization and then the results cached in the platform class (thus there is no requirement for the class being invoked to handle caching of the result).
    See Also:
    Original Java code of Google Flogger
    • Method Detail

      • getInstanceFromSystemProperty

        public static <T> T getInstanceFromSystemProperty​(String propertyName,
                                                          Class<T> type)
        Attempts to get an instance of the given type that is specified by the given propertyName, returning null if that is not possible for any reason.

        The property's value, if present, is expected to be one of:

        1. A fully-qualified class name, in which case the instance is obtained by invoking the class's no-arg static getInstance method, if present, or public no-arg constructor.
        2. A fully-qualified class name followed by # and a method name, in which case the instance is obtained by invoking a no-arg static method of that name, if present, or a public no-arg constructor if not present.
      • getInstanceFromSystemProperty

        public static <T> @Nullable T getInstanceFromSystemProperty​(String propertyName,
                                                                    @Nullable String defaultValue,
                                                                    Class<T> type)
        Attempts to get an instance of the given type that is specified by the given propertyName, returning null if that is not possible for any reason.

        The property's value, if present, or the given defaultValue, is expected to be one of:

        1. A fully-qualified class name, in which case the instance is obtained by invoking the class's no-arg static getInstance method, if present, or public no-arg constructor.
        2. A fully-qualified class name followed by # and a method name, in which case the instance is obtained by invoking a no-arg static method of that name, if present, or a public no-arg constructor if not present.