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

      @Nullable public static 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.