public class ClassUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static ClassLoader |
addJarsOrDirectoriesToClasspath(ClassLoader classLoader,
List<File> jarFiles)
Adds these jars or directories to the classpath.
|
static String |
getLocationOnDisk(Class<?> aClass)
Retrieves the physical location on disk of this class.
|
static String |
getStaticFieldValue(String className,
String fieldName,
ClassLoader classLoader)
Gets the String value of a static field.
|
static <T> T |
instantiate(Class<T> clazz)
Creates a new instance of this class.
|
static <T> T |
instantiate(String className,
ClassLoader classLoader)
Creates a new instance of this class.
|
static <T> List<T> |
instantiateAll(String[] classes,
ClassLoader classLoader)
Instantiate all these classes.
|
static boolean |
isPresent(String className,
ClassLoader classLoader)
Determine whether the
Class identified by the supplied name is present
and can be loaded. |
static <I> Class<? extends I> |
loadClass(Class<I> implementedInterface,
String className,
ClassLoader classLoader)
Loads the class with this name using the class loader.
|
public static <T> T instantiate(String className, ClassLoader classLoader)
T - The type of the new instance.className - The fully qualified name of the class to instantiate.classLoader - The ClassLoader to use.ScannerException - Thrown when the instantiation failed.public static <T> T instantiate(Class<T> clazz)
T - The type of the new instance.clazz - The class to instantiate.ScannerException - Thrown when the instantiation failed.public static <T> List<T> instantiateAll(String[] classes, ClassLoader classLoader)
T - The common type for all classes.classes - A fully qualified class names to instantiate.classLoader - The ClassLoader to use.public static boolean isPresent(String className, ClassLoader classLoader)
Class identified by the supplied name is present
and can be loaded. Will return false if either the class or
one of its dependencies is not present or cannot be loaded.className - The name of the class to check.classLoader - The ClassLoader to use.public static <I> Class<? extends I> loadClass(Class<I> implementedInterface, String className, ClassLoader classLoader)
implementedInterface - The interface the class is expected to implement.className - The name of the class to load.classLoader - The ClassLoader to use.null if it could not be loaded.public static String getLocationOnDisk(Class<?> aClass)
aClass - The class to get the location for.public static ClassLoader addJarsOrDirectoriesToClasspath(ClassLoader classLoader, List<File> jarFiles)
classLoader - The current ClassLoader.jarFiles - The jars or directories to add.public static String getStaticFieldValue(String className, String fieldName, ClassLoader classLoader)
className - The fully qualified name of the class to instantiate.classLoader - The ClassLoader to use.fieldName - The field nameScannerException - Thrown when the instantiation failed.Copyright © 2022. All rights reserved.