Package io.hawt.util
Class ReflectionHelper
- java.lang.Object
-
- io.hawt.util.ReflectionHelper
-
public final class ReflectionHelper extends Object
-
-
Constructor Summary
Constructors Constructor Description ReflectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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.
-
-
-
Method Detail
-
newInstance
public static <T> T newInstance(Class<T> type)
A helper method to create a new instance of a type using the default constructor arguments.
-
invokeMethod
public static Object invokeMethod(Method method, Object instance, Object... parameters)
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
-
-