Package org.springframework.data.util
Class ClassUtils
java.lang.Object
org.springframework.data.util.ClassUtils
Utility class to work with classes.
- Since:
- 3.5
- Author:
- Oliver Gierke, Mark Paluch, Johannes Englmeier
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
ifPresent
(String className, ClassLoader classLoader, Consumer<Class<?>> action) static Class<?>
loadIfPresent
(String name, ClassLoader classLoader) Loads the class with the given name using the givenClassLoader
.
-
Method Details
-
ifPresent
public static void ifPresent(String className, @Nullable ClassLoader classLoader, Consumer<Class<?>> action) Determine whether theClass
identified by the suppliedclassName
is present and can be loaded and call theaction
if theClass
could be loaded.- Parameters:
className
- the name of the class to check.classLoader
- the class loader to use (can be null, which indicates the default class loader).action
- the action callback to notify.- Throws:
IllegalStateException
- if the corresponding class is resolvable but there was a readability mismatch in the inheritance hierarchy of the class (typically a missing dependency declaration in a Jigsaw module definition for a superclass or interface implemented by the class to be checked here)
-
loadIfPresent
Loads the class with the given name using the givenClassLoader
.- Parameters:
name
- the name of the class to be loaded.classLoader
- the class loader to use (can be null, which indicates the default class loader).- Returns:
- the
Class
or null in case the class can't be loaded for any reason.
-