Package io.hawt.util

Class ReflectionHelper


  • public final class ReflectionHelper
    extends Object
    • Constructor Detail

      • ReflectionHelper

        public ReflectionHelper()
    • 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 as RuntimeException instances
        Parameters:
        method - the method to invoke
        instance - 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 on
        annotationType - the annotation type
        checkMetaAnnotations - check for meta annotations
        Returns:
        true if annotations is present