Class ClassUtils

java.lang.Object
org.springframework.data.util.ClassUtils

public abstract class ClassUtils extends Object
Utility class to work with classes.
Since:
3.5
Author:
Oliver Gierke, Mark Paluch, Johannes Englmeier
  • Method Details

    • ifPresent

      public static void ifPresent(String className, @Nullable ClassLoader classLoader, Consumer<Class<?>> action)
      Determine whether the Class identified by the supplied className is present and can be loaded and call the action if the Class 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

      public static @Nullable Class<?> loadIfPresent(String name, @Nullable ClassLoader classLoader)
      Loads the class with the given name using the given ClassLoader.
      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.
    • getDeclaredConstructorIfAvailable

      public 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 return null).

      Essentially translates NoSuchMethodException to null.

      Parameters:
      clazz - the clazz to analyze
      paramTypes - the parameter types of the method
      Returns:
      the constructor, or null if not found
      Since:
      4.0
      See Also: