public final class Classes
extends java.lang.Object
限定符和类型 | 方法和说明 |
---|---|
static java.lang.Class |
forName(java.lang.String fqcn)
Attempts to load the specified class name from the current thread's
context class loader , then the
current ClassLoader (Classes.class.getClassLoader() ), then the system/application
ClassLoader (ClassLoader.getSystemClassLoader() , in that order. |
static <T> java.lang.reflect.Constructor<T> |
getConstructor(java.lang.Class<T> clazz,
java.lang.Class... argTypes) |
static java.io.InputStream |
getResourceAsStream(java.lang.String name)
Returns the specified resource by checking the current thread's
context class loader , then the
current ClassLoader (Classes.class.getClassLoader() ), then the system/application
ClassLoader (ClassLoader.getSystemClassLoader() , in that order, using
getResourceAsStream(name) . |
static <T> T |
instantiate(java.lang.reflect.Constructor<T> ctor,
java.lang.Object... args) |
static boolean |
isAvailable(java.lang.String fullyQualifiedClassName) |
static <T> T |
newInstance(java.lang.Class<T> clazz) |
static <T> T |
newInstance(java.lang.Class<T> clazz,
java.lang.Object... args) |
static java.lang.Object |
newInstance(java.lang.String fqcn) |
static java.lang.Object |
newInstance(java.lang.String fqcn,
java.lang.Object... args) |
public static java.lang.Class forName(java.lang.String fqcn) throws UnknownClassException
context class loader
, then the
current ClassLoader (Classes.class.getClassLoader()
), then the system/application
ClassLoader (ClassLoader.getSystemClassLoader()
, in that order. If any of them cannot locate
the specified class, an UnknownClassException
is thrown (our RuntimeException equivalent of
the JRE's ClassNotFoundException
.fqcn
- the fully qualified class name to loadUnknownClassException
- if the class cannot be found.public static java.io.InputStream getResourceAsStream(java.lang.String name)
context class loader
, then the
current ClassLoader (Classes.class.getClassLoader()
), then the system/application
ClassLoader (ClassLoader.getSystemClassLoader()
, in that order, using
getResourceAsStream(name)
.name
- the name of the resource to acquire from the classloader(s).null
if the resource cannot be found from any
of the three mentioned ClassLoaders.public static boolean isAvailable(java.lang.String fullyQualifiedClassName)
public static java.lang.Object newInstance(java.lang.String fqcn)
public static java.lang.Object newInstance(java.lang.String fqcn, java.lang.Object... args)
public static <T> T newInstance(java.lang.Class<T> clazz)
public static <T> T newInstance(java.lang.Class<T> clazz, java.lang.Object... args)
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> clazz, java.lang.Class... argTypes)
public static <T> T instantiate(java.lang.reflect.Constructor<T> ctor, java.lang.Object... args)