public class ClassUtils extends Object
Class
es, such as acquiring them from the
application ClassLoader
s and instantiating Objects from them.Constructor and Description |
---|
ClassUtils() |
Modifier and Type | Method and Description |
---|---|
static Class |
forName(String fqcn)
Attempts to load the specified class name from the current thread's
context class loader , then the
current ClassLoader (ClassUtils.class.getClassLoader() ), then the system/application
ClassLoader (ClassLoader.getSystemClassLoader() , in that order. |
static List<Method> |
getAnnotatedMethods(Class<?> type,
Class<? extends Annotation> annotation) |
static Constructor |
getConstructor(Class clazz,
Class... argTypes) |
static InputStream |
getResourceAsStream(String name)
Returns the specified resource by checking the current thread's
context class loader , then the
current ClassLoader (ClassUtils.class.getClassLoader() ), then the system/application
ClassLoader (ClassLoader.getSystemClassLoader() , in that order, using
getResourceAsStream(name) . |
static Object |
instantiate(Constructor ctor,
Object... args) |
static boolean |
isAvailable(String fullyQualifiedClassName) |
static Object |
newInstance(Class clazz) |
static Object |
newInstance(Class clazz,
Object... args) |
static Object |
newInstance(String fqcn) |
static Object |
newInstance(String fqcn,
Object... args) |
public ClassUtils()
public static InputStream getResourceAsStream(String name)
context class loader
, then the
current ClassLoader (ClassUtils.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 Class forName(String fqcn) throws UnknownClassException
context class loader
, then the
current ClassLoader (ClassUtils.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 boolean isAvailable(String fullyQualifiedClassName)
public static Object newInstance(String fqcn)
public static Object newInstance(String fqcn, Object... args)
public static Object newInstance(Class clazz)
public static Object newInstance(Class clazz, Object... args)
public static Constructor getConstructor(Class clazz, Class... argTypes)
public static Object instantiate(Constructor ctor, Object... args)
public static List<Method> getAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation)
type
- annotation
- Copyright © 2004-2016 The Apache Software Foundation. All Rights Reserved.