Class ReflectionUtil


  • public final class ReflectionUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> @NonNull java.util.Collection<T> createImplementations​(java.lang.Class<T> interfaceOrSuperClass, java.lang.String packageName)
      Find all implementations of passed type and create it via non-arg constructor.
      static <T> @NonNull java.util.Collection<java.lang.Class<T>> findImplementations​(java.lang.Class<T> interfaceOrSuperClass, java.lang.String packageName)
      Find all implementations of passed type.
      static @NonNull java.util.Optional<java.lang.Class<?>> findOneClassBySimpleNameInJdk​(java.lang.String classSimpleName)
      Find class in JDK packages by his simple name.
      static @NonNull java.util.Collection<java.lang.Class<?>> getGenericTypes​(java.lang.reflect.Field field)
      Get collection of parameters types of passed Field.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getGenericTypes

        @NonNull
        public static @NonNull java.util.Collection<java.lang.Class<?>> getGenericTypes​(@Nullable
                                                                                        java.lang.reflect.Field field)
        Get collection of parameters types of passed Field. You can get generic types only from Field (or Class). For object this information is been removed. Null-safe.
        Parameters:
        field - field with parameters type
        Returns:
        collection of generic types
      • createImplementations

        @NonNull
        public static <T> @NonNull java.util.Collection<T> createImplementations​(@Nullable
                                                                                 java.lang.Class<T> interfaceOrSuperClass,
                                                                                 @Nullable
                                                                                 java.lang.String packageName)
        Find all implementations of passed type and create it via non-arg constructor. Null-safe.
        Type Parameters:
        T - Expected type
        Parameters:
        interfaceOrSuperClass - Base type
        packageName - full package name to search
        Returns:
        Collection of children.
      • findImplementations

        @NonNull
        public static <T> @NonNull java.util.Collection<java.lang.Class<T>> findImplementations​(@Nullable
                                                                                                java.lang.Class<T> interfaceOrSuperClass,
                                                                                                @Nullable
                                                                                                java.lang.String packageName)
        Find all implementations of passed type. Null-safe.
        Type Parameters:
        T - Expected type
        Parameters:
        interfaceOrSuperClass - Base type
        packageName - full package name to search
        Returns:
        Collection of children.
      • findOneClassBySimpleNameInJdk

        @NonNull
        public static @NonNull java.util.Optional<java.lang.Class<?>> findOneClassBySimpleNameInJdk​(@Nullable
                                                                                                    java.lang.String classSimpleName)
        Find class in JDK packages by his simple name. Search will be only in 'java.lang' and 'java.util' because. For example 'String' will find String class. Null-safe.
        Parameters:
        classSimpleName - Simple class name (not full) in JDK.
        Returns:
        Related class