Class ReflectionUtils

java.lang.Object
org.apache.commons.crypto.utils.ReflectionUtils

public final class ReflectionUtils extends Object
General utility methods for working with reflection.
  • Field Details

  • Constructor Details

    • ReflectionUtils

      private ReflectionUtils()
      The private constructor of ReflectionUtils.
  • Method Details

    • getClassByName

      public static Class<?> getClassByName(String name) throws ClassNotFoundException
      Loads a class by name.
      Parameters:
      name - the class name.
      Returns:
      the class object.
      Throws:
      ClassNotFoundException - if the class is not found.
    • getClassByNameOrNull

      private static Class<?> getClassByNameOrNull(String name)
      Loads a class by name, returning null rather than throwing an exception if it couldn't be loaded. This is to avoid the overhead of creating an exception.
      Parameters:
      name - the class name.
      Returns:
      the class object, or null if it could not be found.
    • newInstance

      public static <T> T newInstance(Class<T> klass, Object... args)
      Uses the constructor represented by this Constructor object to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters.
      Type Parameters:
      T - type for the new instance
      Parameters:
      klass - the Class object.
      args - array of objects to be passed as arguments to the constructor call.
      Returns:
      a new object created by calling the constructor this object represents.