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 SummaryModifier and TypeMethodDescriptionstatic <T> @Nullable Constructor<T>getDeclaredConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) Determine whether the given class has a public constructor with the given signature, and return it if available (else returnnull).static voidifPresent(String className, @Nullable ClassLoader classLoader, Consumer<Class<?>> action) static @Nullable Class<?>loadIfPresent(String name, @Nullable ClassLoader classLoader) Loads the class with the given name using the givenClassLoader.
- 
Method Details- 
ifPresentpublic static void ifPresent(String className, @Nullable ClassLoader classLoader, Consumer<Class<?>> action) Determine whether theClassidentified by the suppliedclassNameis present and can be loaded and call theactionif theClasscould 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)
 
- 
loadIfPresentLoads 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 Classor null in case the class can't be loaded for any reason.
 
- 
getDeclaredConstructorIfAvailablepublic static <T> @Nullable Constructor<T> getDeclaredConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) Determine whether the given class has a public constructor with the given signature, and return it if available (else returnnull).Essentially translates NoSuchMethodExceptiontonull.- Parameters:
- clazz- the clazz to analyze
- paramTypes- the parameter types of the method
- Returns:
- the constructor, or nullif not found
- Since:
- 4.0
- See Also:
 
 
-