Package com.norconex.commons.lang
Class ClassUtil
java.lang.Object
com.norconex.commons.lang.ClassUtil
Class-related utility methods.
- Since:
- 2.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A extends Annotation>
AgetAnnotation(Class<?> annotatedClass, Class<A> annotationClass) Gets a type annotation, considering super classes.static <T> TnewInstance(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.
-
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 classannotationClass- the annotation class we are looking for- Returns:
- an annotation, or
nullif none is found
-
newInstance
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 instantiateargs- constructor arguments- Returns:
- new instance of the class or
nullif class isnull - Throws:
IllegalArgumentException- wrapper exception for checked exceptions thrown when the class cannot be instantiated with the supplied arguments- Since:
- 3.0.0
-