@Typed public abstract class ClassUtils extends Object
ClassLoader
and Manifest
handlingModifier and Type | Method and Description |
---|---|
static boolean |
containsMethod(Class<?> targetClass,
Method method)
Checks if the given class contains a method with the same signature.
|
static boolean |
containsPossiblyGenericMethod(Class<?> targetClass,
Method method)
Checks if the given class has a method with the same signature, taking in to account generic types
|
static Method |
extractMethod(Class<?> clazz,
Method sourceMethod)
Extracts a method with same signature as the source method.
|
static Method |
extractPossiblyGenericMethod(Class<?> clazz,
Method sourceMethod)
Extracts a method matching the source method, allowing generic type parameters to be substituted as
long as they are properly castable.
|
static ClassLoader |
getClassLoader(Object o)
Detect the right ClassLoader.
|
static String |
getJarVersion(Class targetClass)
Reads the version of the jar which contains the given class
|
static String |
getRevision(Class targetClass)
Reads the VCS revision which was used for creating the jar
|
static Object |
instantiateClassForName(String className)
Creates an instance for the given class-name
|
static Class |
loadClassForName(String name)
Loads class for the given name
|
static <T> T |
tryToInstantiateClass(Class<T> targetClass)
Instantiates a given class via the default constructor
|
static Object |
tryToInstantiateClassForName(String className)
Tries to instantiate a class for the given name via the default constructor
|
static <T> T |
tryToInstantiateClassForName(String className,
Class<T> targetType)
Tries to instantiate a class for the given name and type via the default constructor
|
static Class |
tryToLoadClassForName(String name)
Tries to load a class based on the given name
|
static <T> Class<T> |
tryToLoadClassForName(String name,
Class<T> targetType)
Tries to load a class based on the given name and interface or abstract class.
|
static <T> Class<T> |
tryToLoadClassForName(String name,
Class<T> targetType,
ClassLoader classLoader)
Tries to load a class based on the given name and interface or abstract class.
|
static Class |
tryToLoadClassForName(String name,
ClassLoader classLoader)
Tries to load a class based on the given name
|
public static ClassLoader getClassLoader(Object o)
o
- if not null
it may get used to detect the classloader.ClassLoader
which should get used to create new instancespublic static <T> Class<T> tryToLoadClassForName(String name, Class<T> targetType)
T
- current typename
- name of the concrete classtargetType
- target type (interface or abstract class)public static <T> Class<T> tryToLoadClassForName(String name, Class<T> targetType, ClassLoader classLoader)
T
- current typename
- name of the concrete classtargetType
- target type (interface or abstract class)classLoader
- The ClassLoader
.public static Class tryToLoadClassForName(String name)
name
- name of the classnull
if it isn't in the classpathpublic static Class tryToLoadClassForName(String name, ClassLoader classLoader)
name
- name of the classclassLoader
- The ClassLoader
.null
if it isn't in the classpathpublic static Class loadClassForName(String name) throws ClassNotFoundException
name
- name of the classClassNotFoundException
- if the class can't be loadedpublic static <T> T tryToInstantiateClass(Class<T> targetClass)
T
- current typetargetClass
- class which should be instantiatedpublic static <T> T tryToInstantiateClassForName(String className, Class<T> targetType)
T
- current typeclassName
- name of the classtargetType
- target typepublic static Object tryToInstantiateClassForName(String className)
className
- name of the classpublic static Object instantiateClassForName(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException
className
- name of the class which should be instantiatedClassNotFoundException
- if the instantiation failedIllegalAccessException
- if the instantiation failedInstantiationException
- if the instantiation failedpublic static String getJarVersion(Class targetClass)
targetClass
- class within the jarpublic static String getRevision(Class targetClass)
targetClass
- class within the jarpublic static boolean containsMethod(Class<?> targetClass, Method method)
targetClass
- The class to checkmethod
- The source methodpublic static Method extractMethod(Class<?> clazz, Method sourceMethod)
clazz
- The target classsourceMethod
- The source method.null
public static boolean containsPossiblyGenericMethod(Class<?> targetClass, Method method)
targetClass
- method
- public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod)
clazz
- The target classsourceMethod
- The source method.null
Copyright © 2016 The Apache Software Foundation. All rights reserved.