Class BambooReflectionUtils


  • public class BambooReflectionUtils
    extends Object
    Utility methods related to Java reflection API.
    • Constructor Detail

      • BambooReflectionUtils

        public BambooReflectionUtils()
    • Method Detail

      • instantiateQuietly

        @NotNull
        public static <T> T instantiateQuietly​(@NotNull
                                               @NotNull Class<T> aClass)
        Instantiates a class quietly, throwing all possible exceptions as RuntimeException. Uses Class.newInstance() method to instantiate class.
        Type Parameters:
        T - type of the object to be instantiated
        Parameters:
        aClass - class to be instantiated.
        Returns:
        instantiated object of the given class
        Throws:
        RuntimeException - if any exceptions occurred while instantiating the class (e.g. InstantiationException or IllegalAccessException), RuntimeException will be thrown as a wrapping exception.
      • getSimpleType

        public static Class<?> getSimpleType​(@NotNull
                                             @NotNull Class<?> aClass)
        Parameters:
        aClass -
        Returns:
        simple type for arrays, for example for java.lang.String[] class it will return java.lang.String
      • getAllDeclaredFields

        public static List<Field> getAllDeclaredFields​(@NotNull
                                                       @NotNull Class<?> clazz)
        Returns all fields declared in the supplied class and its superclasses.
      • getAllDeclaredMethods

        public static List<Method> getAllDeclaredMethods​(Class<?> clazz)
        Returns all methods declared in the supplied class and its superclasses.
      • hasCustomDeserialisation

        public static boolean hasCustomDeserialisation​(Class<?> clazz)
        Returns true if the class or any of its superclasses contain custom deserialisation method(s). Note: does not take method visibility into account.
      • method2SignatureString

        @NotNull
        public static @NotNull String method2SignatureString​(@NotNull
                                                             @NotNull Method method)
        Returns simplified signature of a method consisting of fully qualified class name, method name and list of argument types.