Class ClassUtil

java.lang.Object
com.norconex.commons.lang.ClassUtil

public final class ClassUtil extends Object
Class-related utility methods.
Since:
2.0.0
  • Method Details

    • getAnnotation

      public static <A extends Annotation> A getAnnotation(Class<?> annotatedClass, Class<A> annotationClass)
      Gets a type annotation, considering super classes. If more than one class in the hierarchy has an annotation of the same type, the first one matching is returned.
      Type Parameters:
      A - annotation type
      Parameters:
      annotatedClass - annotated class
      annotationClass - the annotation class we are looking for
      Returns:
      an annotation, or null if none is found
    • newInstance

      public static <T> T newInstance(Class<T> clazz, Object... args)
      Create a new instance of this class the with supplied arguments and returns an an unchecked exception in case of failure. In case of multiple constructors with the same number of arguments, it will try to find the one matching the argument types.
      Parameters:
      clazz - the class to instantiate
      args - constructor arguments
      Returns:
      new instance of the class or null if class is null
      Throws:
      IllegalArgumentException - wrapper exception for checked exceptions thrown when the class cannot be instantiated with the supplied arguments
      Since:
      3.0.0