Package io.hawt.util
Class ReflectionHelper
java.lang.Object
io.hawt.util.ReflectionHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasAnnotation(AnnotatedElement elem, Class<? extends Annotation> annotationType, boolean checkMetaAnnotations) Checks if a Class or Method are annotated with the given annotationstatic booleanhasMethodWithAnnotation(Class<?> type, Class<? extends Annotation> annotationType, boolean checkMetaAnnotations) Returns true if the given type has a method with the given annotationstatic ObjectinvokeMethod(Method method, Object instance, Object... parameters) A helper method to invoke a method via reflection and wrap any exceptions asRuntimeExceptioninstancesstatic <T> TnewInstance(Class<T> type) A helper method to create a new instance of a type using the default constructor arguments.
-
Constructor Details
-
ReflectionHelper
public ReflectionHelper()
-
-
Method Details
-
newInstance
A helper method to create a new instance of a type using the default constructor arguments. -
invokeMethod
A helper method to invoke a method via reflection and wrap any exceptions asRuntimeExceptioninstances- Parameters:
method- the method to invokeinstance- the object instance (or null for static methods)parameters- the parameters to the method- Returns:
- the result of the method invocation
-
hasMethodWithAnnotation
public static boolean hasMethodWithAnnotation(Class<?> type, Class<? extends Annotation> annotationType, boolean checkMetaAnnotations) Returns true if the given type has a method with the given annotation -
hasAnnotation
public static boolean hasAnnotation(AnnotatedElement elem, Class<? extends Annotation> annotationType, boolean checkMetaAnnotations) Checks if a Class or Method are annotated with the given annotation- Parameters:
elem- the Class or Method to reflect onannotationType- the annotation typecheckMetaAnnotations- check for meta annotations- Returns:
- true if annotations is present
-