public final class Provider extends Object
// Initialize a static variable using reflection.
static final Foo foo = Provider.newInstance("Foo", new NoopFoo());
| Constructor and Description |
|---|
Provider() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
createInstance(Class<?> rawClass,
Class<T> superclass)
Tries to create an instance of the given rawClass as a subclass of the given superclass.
|
static <T> ClassLoader |
getCorrectClassLoader(Class<T> superClass)
Get the correct
ClassLoader that must be used when loading using reflection. |
static <T> T |
newInstance(String name,
T defaultValue)
Returns a new instance of the class specified with
name by invoking the empty-argument
constructor via reflections. |
@Nullable public static <T> T newInstance(String name, @Nullable T defaultValue)
name by invoking the empty-argument
constructor via reflections. If the specified class is not found, the defaultValue is
returned.public static <T> T createInstance(Class<?> rawClass, Class<T> superclass)
rawClass - The class that is initialized.superclass - The initialized class must be a subclass of this.ServiceConfigurationError - if any error happens.public static <T> ClassLoader getCorrectClassLoader(Class<T> superClass)
ClassLoader that must be used when loading using reflection.ClassLoader that must be used when loading using reflection.