Class Classes
java.lang.Object
dk.cloudcreate.essentials.shared.reflection.Classes
Utility class for working with
Class's-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompareTypeSpecificity(Class<?> leftSide, Class<?> rightSide) ComparesleftSidewith therightSidefor 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.static booleandoesClassExistOnClasspath(String fullyQualifiedClassName) Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpathstatic booleandoesClassExistOnClasspath(String fullyQualifiedClassName, ClassLoader classLoader) Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpathstatic Class<?>Load a class based on a fully qualified class name (FQCN)static Class<?>forName(String fullyQualifiedClassName, ClassLoader classLoader) Load a class based on a fully qualified class name (FQCN) and using a specificClassLoadersuperClasses(Class<?> type) Get all superclasses of a type.
-
Constructor Details
-
Classes
public Classes()
-
-
Method Details
-
forName
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 specificClassLoader- Parameters:
fullyQualifiedClassName- the Fully Qualified Class Name (FQCN) as a stringclassLoader- the class loader to use- Returns:
- The class loaded
- Throws:
ReflectionException- in case loading the class failed
-
compareTypeSpecificity
ComparesleftSidewith therightSidefor 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 typerightSide- 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
- negative integer - if the leftSide is less specific then the rightSide
-
superClasses
Get all superclasses of a type.- Parameters:
type- The type to get all super classes for- Returns:
- All superclasses of
type
-
doesClassExistOnClasspath
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 classclassLoader- 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
-