Class Classes


  • public final class Classes
    extends Object
    Utility class for working with Class's
    • Constructor Detail

      • Classes

        public Classes()
    • Method Detail

      • forName

        public static Class<?> forName​(String fullyQualifiedClassName)
                                throws ReflectionException
        Load a class based on a fully qualified class name (FQCN)
        Parameters:
        fullyQualifiedClassName - the Fully Qualified Class Name (FQCN) as a
        Returns:
        The class loaded
        Throws:
        ReflectionException - in case loading the class failed
      • forName

        public static Class<?> forName​(String fullyQualifiedClassName,
                                       ClassLoader classLoader)
                                throws ReflectionException
        Load a class based on a fully qualified class name (FQCN) and using a specific ClassLoader
        Parameters:
        fullyQualifiedClassName - the Fully Qualified Class Name (FQCN) as a string
        classLoader - the class loader to use
        Returns:
        The class loaded
        Throws:
        ReflectionException - in case loading the class failed
      • compareTypeSpecificity

        public static int compareTypeSpecificity​(Class<?> leftSide,
                                                 Class<?> rightSide)
        Compares leftSide with the rightSide for inheritance order.
        It returns:
        • negative integer - if the leftSide is less specific then the rightSide
          Example: If leftSide is a CharSequence and rightSide is a String (a specialization of CharSequence).
        • zero - if the leftSide is equally specific to rightSide (i.e. leftSide and rightSide are the same class)
          Example: If leftSide is a CharSequence and rightSide is a CharSequence
        • negative integer - if the leftSide is more specific then the rightSide
          Example: If leftSide is a String (a subclass of CharSequence) and rightSide is a CharSequence.
        Parameters:
        leftSide - the left side type
        rightSide - the right side type
        Returns:
        the inheritance comparison between the leftSide and rightSide
        Throws:
        IllegalArgumentException - in case leftSide and rightSide aren't either the same class or in a inheritance hierarchy with each other
      • superClasses

        public static List<Class<?>> superClasses​(Class<?> type)
        Get all superclasses of a type.
        Parameters:
        type - The type to get all super classes for
        Returns:
        All superclasses of type
      • doesClassExistOnClasspath

        public static boolean doesClassExistOnClasspath​(String fullyQualifiedClassName)
        Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath
        Parameters:
        fullyQualifiedClassName - the fully qualified name of the class
        Returns:
        true if a class with the given Fully Qualified Class Name (FQCN) exists on the classpath, otherwise false
      • doesClassExistOnClasspath

        public static boolean doesClassExistOnClasspath​(String fullyQualifiedClassName,
                                                        ClassLoader classLoader)
        Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath
        Parameters:
        fullyQualifiedClassName - the fully qualified name of the class
        classLoader - the classloader used to check if the class exist
        Returns:
        true if a class with the given Fully Qualified Class Name (FQCN) exists on the classpath, otherwise false